0
    typedef struct node
{
    bool is_word;
    struct node* children[27];
}node;


node* root;
root = malloc(sizeof(node));

dictionary.c:23:1: error: type specifier missing, defaults to 'int' [-Werror,-Wimplicit-int] root = malloc(sizeof(node));

^ dictionary.c:23:1: error: redefinition of 'root' with a different type: 'int' vs 'node *' (aka 'struct node ') dictionary.c:22:7: note: previous definition is here node root; ^ 2 errors generated. make: *** [dictionary.o] Error 1

1
  • you must not use malloc outside main or any other function – MARS Jul 3 '16 at 14:46
1

Anything that can only be done at run time must be done inside of main or inside of a function. Only statements that can be hard-coded into machine code, such as declarations of global vars can be done outside of main or functions. Thus, the malloc, which assigns a value to a variable as well as allocating memory, cannot be done the way it is shown in the question. Move the malloc to the beginning of load() and it should be fine.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .