Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Address-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!



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: