data structures - Initialise C Struct in Order to Be Used Globally -
i have following struct:
dict.c
typedef struct dictionary { int key; char *word; char *desc; } dict;
main.c
#include "dict.c" dict * d; function() { d->key = 1; }
this throws error: dereferencing pointer incomplete type.
how allow struct read in other functions?
you allocating global pointer, don't. alloc real struct , initialize on declaration:
#include "dict.c" dict d = {.key = 1, .word = &word_data, .desc = &desc_data};
Comments
Post a Comment