Re: C99 Initialisers

From: Jakub Jelinek
Date: Tue Aug 12 2003 - 05:24:49 EST


On Tue, Aug 12, 2003 at 12:03:21PM +0200, Geert Uytterhoeven wrote:
> > > I sure would. Oh, you can drop the .class, .class_mask, and
> > > .driver_data lines, and then it even looks cleaner.
> > Just a quick question. if we drop these, will they _always_
> > be initialised 0 ? I have made a test to see, and it seemed as though,
> > but I would like to be 100% sure.
>
> For globals and static locals: yes.
> For non-static locals: no.

No, for all initializers members which are not explicitely initialized are
zero initialized.
Only if you provide no initializer at all, globals/static locals will
still be zero initializers while non-static locals may contain anything.
So, if you write:

struct A { int a; int b; int c; int d; };
void bar (void *);
void foo (void)
{
struct A a = { .a = 21 };
bar (&a);
}

then it is the same as:

struct A { int a; int b; int c; int d; };
void bar (void *);
void foo (void)
{
struct A a = { .a = 21, .b = 0, .c = 0, .d = 0 };
bar (&a);
}

Jakub
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/