c - Link Lists, invalid application of path to size incomplete type -
im getting invalid application of path size error when compiling code cant find problem myself, can help?
/********************************************************* * node represent packet includes link reference* * link list of nodes pointer packet struct * **********************************************************/ struct node { unsigned int source; unsigned int destination; unsigned int type; int port; char *data; struct packet *next; // link next packet //unassigned int source //unassigned int destination //int type //unassigned int port //char *data //struct node *next link next node }; typedef struct packet node; // removes need refer struct /********************************************************* * stubs declared functions below * **********************************************************/ void outpacket(node **head); void push(node **head, node **apacket); node* pop(node **head); int main() { /********************************************************* * pointers link list , temporary packeyt * * insert list * **********************************************************/ node *ppacket, *phead = null; /********************************************************* * create packet , check heap had room * **********************************************************/ ppacket = (node *)malloc(sizeof(node)); if (ppacket == null) { printf("error: out of memory\n"); exit(1); }
this snipet of full code break point happens on line with:
ppacket = (node *)malloc(sizeof(node));
thanks help
probably because using struct packet
out defining it.
in definition of struct node
, using struct packet*
. ther nothing called struct packed
. either change name of structure, or change element.
try following:
struct packet { unsigned int source; unsigned int destination; unsigned int type; int port; char *data; struct packet *next; // link next packet //unassigned int source //unassigned int destination //int type //unassigned int port //char *data //struct node *next link next node }; typedef struct packet node; // removes need refer struct
here, struct packet
, node
same structure , there no anomaly.