tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Initializer and initialization macros in queue.h



On 2015-08-09 14:26, Joerg Sonnenberger wrote:
> On Fri, Jul 31, 2015 at 10:25:32AM +0000, Matthias-Christian Ott wrote:
>> queue.h defines initializers macros (e.g. LIST_HEAD_INITIALIZER) and
>> initialization macros (e.g. LIST_INIT). The initializer macros have been
>> introduced in NetBSD. I'm not sure how what's the intended purpose of
>> both macro types.
> 
> The head initializer macros allow the globals to be usable directly
> without any runtime initialisation. That can simplify setup logic a lot.

So in the following code head1 and head2 would initialized to the same
value?

#include <stddef.h>
#include <sys/queue.h>

struct entry {
    LIST_ENTRY(entry) link;
};

LIST_HEAD(head, entry);

struct head head1 = LIST_HEAD_INITIALIZER(&head1);

int main(void)
{
    struct head head2;

    LIST_INIT(&head2);

    return 0;
}

And the code would be equivalent to the following:

#include <stddef.h>
#include <sys/queue.h>

struct entry {
    LIST_ENTRY(entry) link;
};

LIST_HEAD(head, entry);

struct head head1;

int main(void)
{
    struct head head2;

    LIST_INIT(&head1);
    LIST_INIT(&head2);

    return 0;
}

Is that right?

- Matthias-Christian


Home | Main Index | Thread Index | Old Index