c - Initializer element is not constant -


i'm trying declare dummy head* global variable ide giving error:

initializer element not constant 

how fix that?

typedef struct mynode{     struct mynode *next;     int value; }node;  //declare global variable node *head = malloc(sizeof(node)); head->next = null; 

the obvious thing declare head variable global initialisation within function.

typedef struct mynode{     struct mynode *next;     int value; } node;  node *head;  int main (int argc, char **argv) {     head = malloc(sizeof *head);     if (!head) {         /* error */         exit(-1);     }      head->next = null;      return 0; } 

Comments

Popular posts from this blog

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -