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 Sat, Sep 12, 2015 at 02:23:38PM +0200, Matthias-Christian Ott wrote:
> 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;
> }
Well, they would of course have different values, but both are
initialised. This is equivalent to your second example, assuming nothing
runs before main.
Joerg
Home |
Main Index |
Thread Index |
Old Index