everyone.
Here is a test program I wrote.
#include <stdio.h>
#include <stdlib.h>
typedef struct _item {
int value;
} item , *pItem;
typedef struct _itemcontainer {
pItem i;
} itemcontainer, *pItemcontainer;
int main(void) {
item i;
i.value = 1;
pItem pi = &i;
pItem* ppi = π
itemcontainer ei = {&i};
pItem* pei = (pItem*)(&ei);
pItem api[1] = {&i};
printf("First case: %d\n", (*ppi)->value);
printf("Second case: %d\n", (*pei)->value);
printf("Third case: %d\n", (*api)->value);
return EXIT_SUCCESS;
}
The three printf functions' results are the same value, i.e. 1. From the code, the initialization of variable ei and api are both {&i}. So I guess pItem* pei = (pItem*)ei should work, however it failed. Could any one tell me the difference between ei and api? It seems to be related with how the compiler deal with struct and array, which I am not good at. I need a concrete explanation. Thanks in advance.
Best Wishes
Jfhu
typedefpointer types. I usetypedef struct name name;in whichstruct namecan be an incomplete type if you want to restrict access to the members, so thatname *is a pointer, andconst name *is a pointer-to-const. I think it's clearer to use the language's given syntax for things like pointers andconsts for this, because a naming scheme will be easier to forget (and harder to Google) than the built-in language syntax. If you usename *, good C programmers will know without thinking that it needs to be cleaned up.