I want to have code that looks something like this…
static linked_list* globalListHoldingAllSortsOfGoodies = initialize_linked_list();
/* [In a different file...] */
static int placeholder = add_to_global_list(goodies);
But non-constant initialization is impossible in C.
Is there some way to get the same affect without breaking C89?
The point is to have different things “automatically register” themselves into the global list by declaring the goodies with a macro that also uses placeholder.
You can build a linked list from static data. In ANSI C89 (aka ISO C90), it could look like this:
In ISO C99 (adopted by ANSI in 2000), you can additionally use compound literals, eg
Mixing statically allocated nodes with dynamically allocated nodes is problematic as freeing the former will result in undefined behaviour, so it will be necessary to keep track of which nodes belong to which group.