Suppose I have the following structure
typedef struct _Stack {
struct _Stack *next;
} Stack;
Note in above there is no data type for storage, only *next pointer to structure. So, my question is will it be possible that the following function is valid.
void stackPush(Stack **stackP, void *dataP) {
Stack *data = (Stack*)dataP;
data->next = *stackP;
*stackP = data;
}
I saw this function in glib library in the file gtrashstack.c. But when I compiled above, I got a warning : In data->next : assignment from incompatible pointer type.
I know that, I can rewrite the structure with generic pointer. But I only want to know, why the above will not work?
Update: My mistake, here I write typedef struct _Stack but in my program, I missed _Stack.
data->next = *stackPshould probably be writtendata->next = &(stackP->next);ordata->next = (struct _Stack *) *stackP;.data->next = (Stack *)*stackPdata->nextis of typestruct _Stack *, notStack *._Stackintypedef structin my original program