C99 struct initialization (C99/gcc)

J

jilerner

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.
 
E

Emmanuel Delahaye

(e-mail address 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.
 
C

Chris Torek

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

Question about C99/gcc struct initialization:

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. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top