lkml.org 
[lkml]   [2003]   [Aug]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: C99 Initialisers
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@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:47    [W:0.186 / U:0.016 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site