Velocity Reviews > C99 struct initialization (C99/gcc)

# C99 struct initialization (C99/gcc)

jilerner@yahoo.com
Guest
Posts: n/a

 02-05-2006

void ffoo(void) {
struct FOO { int a,b,c; };
struct foo = { .b = 22 };

What happens now to foo.a and foo.c ? Are they initialized to 0,
or left unitialized ?

Y.L.

Emmanuel Delahaye
Guest
Posts: n/a

 02-05-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) a écrit :
> Question about C99/gcc struct initialization:
>
> void ffoo(void) {
> struct FOO { int a,b,c; };
> struct foo = { .b = 22 };

Handy, isn't it ?

> What happens now to foo.a and foo.c ? Are they initialized to 0,

Yes.

> or left unitialized ?

No.

--
A+

Emmanuel Delahaye

Abhishek
Guest
Posts: n/a

 02-05-2006
Thats one good thing you get with C99.

(E-Mail Removed) wrote:
> Question about C99/gcc struct initialization:
>
> void ffoo(void) {
> struct FOO { int a,b,c; };
> struct foo = { .b = 22 };
>
> What happens now to foo.a and foo.c ? Are they initialized to 0,
> or left unitialized ?
>
> Y.L.

Chris Torek
Guest
Posts: n/a

 02-20-2006
(I saved this to reply to later, in case no one else did. I saw
no useful replies, so here is one.)

In article <(E-Mail Removed). com>
<(E-Mail Removed)> wrote:
>
>void ffoo(void) {
> struct FOO { int a,b,c; };
> struct foo = { .b = 22 };

This is a syntax error. Presumably you mean:

struct FOO foo = { .b = 22 };

>What happens now to foo.a and foo.c ? Are they initialized to 0,
>or left unitialized ?

In C99, unmentioned members of an otherwise-initialized aggregate
are initialized to zero. So foo.a and foo.c are set to 0.

What GNUC does with them is off-topic.
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
Reading email is like searching for food in the garbage, thanks to spammers.