Question
I need to define a data structure with these constraints:
- in C (C99 okay)
- one structure (struct) instance containing a number of structure instances containing pointers to other structure instances (a graph structure, but conceptually a doubly linked list is enough to illustrate the point)
- the whole structure must be statically allocated at compile time (not address in memory, that would be linking, but full memory layout of the whole structure including pointers)
- all fields are declared constant (including pointers)
- some references are forward, some backwards. IOW, when parsing the declaration, some pointers refer to fields that have not yet been parsed (but since the structure is known by the compiler, the layout in memory is already known).
- portability, standard-compliance a big plus.
Search before you post
I did it, but since I hesitated and found no easy reference, this question serves to help my future self and all others who need the same.
Metaphor
Fun fact: to obey all these constraints feels like folding a cardboard box top: once it's done it fits tightly, but it has to fit all the parts or it does not work.
( picture credits https://www.youtube.com/watch?v=H5oOBLSJzGM )