Note that there are some explanatory texts on larger screens.

plurals
  1. POCan I get a pointer to a struct as a parameter from a function in C?
    text
    copied!<p>I have a type defined like this:</p> <pre><code>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 </code></pre> <p>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:</p> <pre><code>int MyHashtableGet(MyHashtable_t Hashtable, void *Key, void *Value) { void *Row = NULL; int RetValue = -1; MakeRow(Hashtable, Key, NULL, &amp;Row); if (!MyStoreSelect(Hashtable-&gt;TableId, Row)) { switch (Hashtable-&gt;ValueType) { case MY_HASHTABLE_TYPE_INT: *(int *)Value = *(int *)((char *)Row + Hashtable-&gt;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-&gt;KeySize); break; } } MyFree(Row); return RetValue; } </code></pre> <p>that work for int. But not for pointer when I try to get Dyntab_t. This works if I use function</p> <pre><code>void *MyHashtableGetPointer(MyHashtable_t Hashtable, void *Key) { void *Row = NULL; void *RetValue = NULL; MakeRow(Hashtable, Key, NULL, &amp;Row); if (!MyStoreSelect(Hashtable-&gt;TableId, Row)) RetValue = *(void **)*(int **)((char *)Row + Hashtable-&gt;KeySize); MyFree(Row); return RetValue; } </code></pre> <p>when I call it with:</p> <pre><code>int Key = 1; DynTab_t MyTab; MyTab = (DynTab_t)MyHashtableGetPointer(MyHashtable, &amp;Key); </code></pre> <p>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. </p> <p>Thanks &amp; BR -Matti </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload