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

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -