Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6859063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:14:14+00:00 2026-05-27T02:14:14+00:00

I have a type defined like this: struct DynTab_s { int object_count; //other fields

  • 0

I have a type defined like this:

struct DynTab_s {
    int     object_count;
    //other fields
    void    *data;
};

typedef struct DynTab_s *Dyntab_t; //note that type I use is pointer to struct

I have a storage utility that I can user to store and retrieve them. I’ve chosen to support int, double and pointer type. I have a function to retrieve the int and double values by key:

int MyHashtableGet(MyHashtable_t Hashtable, void *Key, void *Value)
{   
    void    *Row = NULL;
    int     RetValue = -1;

    MakeRow(Hashtable, Key, NULL, &Row);
    if (!MyStoreSelect(Hashtable->TableId, Row))
    {
        switch (Hashtable->ValueType)
        {
        case MY_HASHTABLE_TYPE_INT: 
            *(int *)Value = *(int *)((char *)Row + Hashtable->KeySize);
            break;
        case MY_HASHTABLE_TYPE_POINTER:
            //after row below I can see the DynTab_t in the item when I cast it
            Value = *(void **)*(int **)((char *)Row + Hashtable->KeySize);
        break;
        }
    }
    MyFree(Row);

    return RetValue;
}

that work for int. But not for pointer when I try to get Dyntab_t. This works if I use function

void *MyHashtableGetPointer(MyHashtable_t Hashtable, void *Key)
{
    void        *Row = NULL;
    void        *RetValue = NULL;

    MakeRow(Hashtable, Key, NULL, &Row);
    if (!MyStoreSelect(Hashtable->TableId, Row))
        RetValue = *(void **)*(int **)((char *)Row + Hashtable->KeySize);

    MyFree(Row);

    return RetValue;
}

when I call it with:

int       Key = 1;
DynTab_t  MyTab;

MyTab = (DynTab_t)MyHashtableGetPointer(MyHashtable, &Key);

The question is can I at all use this MyHashtableGet to get DynTab_t item or does second parameter have to be void ** type? If yes, can you please provide the exact syntax to call and to MyHashtableGet in case of MY_HASHTABLE_TYPE_POINTER.

Thanks & BR -Matti

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:14:14+00:00Added an answer on May 27, 2026 at 2:14 am

    The question is can I at all use this MyHashtableGet to get DynTab_t item or does second parameter have to be void ** type?

    The only difference (if you’re storing the pointers like you store the int values) would be that when retrieving an int, you’d pass the address of an int variable; and when retrieving a pointer, you’d pass the address of a pointer variable. A void * can hold the address of anything (except functions sometimes) — including other pointers. So the last parameter is fine as void *, as long as you handle it appropriately elsewhere.

    I’m not sure what you’re doing in your function, though. If you store the pointers the same way as the ints in your data structure, so that at the same level of indirection you’d have an int for the integer type and a void * for the pointer type, then why are they dereferenced to different levels?

        case MY_HASHTABLE_TYPE_INT: 
            *(int *)Value = *(int *)((char *)Row + Hashtable->KeySize);
            break;
    

    In the above, it seems that ((char *)Row + Hashtable->KeySize) gets you the pointer to whatever value you’ve stored, though of the wrong pointer type. Then the (int *) casts to a pointer of your data’s type (int in this case), which you then dereference and assign to what Value points to.

        case MY_HASHTABLE_TYPE_POINTER:
            Value = *(void **)*(int **)((char *)Row + Hashtable->KeySize);
        break;
    

    But here, you cast to int **, dereference, cast to void **, then dereference again, and assign to Value instead of what Value points at? Isn’t that one too many dereferences? Shouldn’t you assign to the target of Value rather than Value? And why do you need to cast to int ** at all? I think it should be more like this:

        case MY_HASHTABLE_TYPE_POINTER:
            *(void **)Value = *(void **)((char *)Row + Hashtable->KeySize);
            break;
    

    Then, when calling to get an int:

    ...
    int       Val;
    MyHashtableGet(Table, Key, &Val);
    

    …and when calling to get a pointer:

    ...
    void      *Val;
    MyHashtableGet(Table, Key, &Val);
    

    Edit:
    This assumes one of two things, though: That the the variable you passed the address of in Value is void *, or that the variable you passed the address of is of a type that is internally represented the same way as void * (often true, but not guaranteed). If you want to rely on the pointer type being converted on assignment (in case their representations differ), you could implement your MyHashtableGetPointer() function as a wrapper for MyHashtableGet():

    void *MyHashtableGetPointer(MyHashtable_t Hashtable, void *Key)
    {
      void *res = NULL;
      MyHashtableGet(Hashtable, Key, &res);
      return res;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a structure defined like so: typedef struct { int n; int *n_p;
I have a standalone enum type defined, something like this: package my.pkg.types; public enum
I have a ComponentResourceKey defined in my resource dictionary like this: <Style x:Key={ComponentResourceKey TypeInTargetAssembly={x:Type
I have a class here that is defined like this: struct USERFPOINT { POINTFLOAT
I have a set of structs, defined as follows: typedef struct { int index;
I have a map defined like this std::map<some_key_type, std::string::iterator> mIteratorMap; And a huge string
I've got a structure defined inside header.h that looks like : typedef struct {
If I have a type defined as a set of an enumerated type, it's
I have a complex type defined which doesn't currently contain any minOccurs restrictions. When
I have a default concrete type defined in a registry: ForRequestedType<IXRepository>() .TheDefaultIsConcreteType<CacheXRepository>(); The ChaceXRepository

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.