4 ms·
When using variable-length arrays (which I know are being phased out but which still do exist in the language) sizeof is indeed evaluated at runtime. It's weird
by unwind 3y ago
When using variable-length arrays (which I know are being phased out but which still do exist in the language) sizeof is indeed evaluated at runtime. It's weird.
- kazinator 3y agoAddress-of (&) can be resolved at load time, making this possible at file scope: struct node { struct node *next, *prev; } circular_list = { &circular_list, &circular_list }; This requires no initialization code to run; linking resolves it. Very long ago I made a GUI help system for a program, where all the documentation nodes were represented as structures with pointers for their navigation links: next section, previous section, up, children ... I statically declared the entire content with declarations akin to the above circular_list. The help GUI was just a window which displayed the node contents, and the buttons like next and prev just chased the pointers to another node which would replace the displayed content. Worked like a charm. Good luck giving that to internationalization people to translate. Haha!