# C99 struct initialization (C99/gcc)

Discussion in 'C Programming' started by jilerner@yahoo.com, Feb 5, 2006.

1. ### Guest

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.

, Feb 5, 2006

2. ### Emmanuel DelahayeGuest

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

Emmanuel Delahaye, Feb 5, 2006

3. ### AbhishekGuest

Thats one good thing you get with C99.

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.

Abhishek, Feb 5, 2006
4. ### Chris TorekGuest

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

In article <>
<> 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