I found many answers to this question in C ++, but I'm very interested in C.
I have a circular linked list in C and I want to initialize it with a dummy node header before it is first available. A dummy node header is a statically assigned global variable. This is my current solution:
static once = 1; if(once){ once = 0;
This works, but I have to put it in every function that uses this linked list. (Of course, I can put this code in my own function, so I only need to call this function in any other function, but this is not much better). Is there a better way? For example, if I have the following structure:
struct node { int value; struct node *next; }
Is it possible to initialize one of these structures as a literal so that its next value points to itself?
In the Initialize as Literal section, I mean the following: (Sorry, probably the wrong terminology)
struct test { int i; double d; }; struct test magic = {1, 2.3};
c static
ItsTimaiFool
source share