Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > C99 struct initialization (C99/gcc)

Reply
Thread Tools

C99 struct initialization (C99/gcc)

 
 
jilerner@yahoo.com
Guest
Posts: n/a
 
      02-05-2006
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.

 
Reply With Quote
 
 
 
 
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
 
Reply With Quote
 
 
 
 
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.


 
Reply With Quote
 
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:
>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.
--
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
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can *common* struct-members of 2 different struct-types, that are thesame for the first common members, be accessed via pointer cast to either struct-type? John Reye C Programming 28 05-08-2012 12:24 AM
Difference between "library parts" of C99 and "language parts" of C99 albert.neu@gmail.com C Programming 3 03-31-2007 08:14 PM
static struct initialization in a Class:: -- not my struct christian.bongiorno@gmail.com C++ 2 09-20-2006 06:53 PM
struct my_struct *p = (struct my_struct *)malloc(sizeof(struct my_struct)); Chris Fogelklou C Programming 36 04-20-2004 08:27 AM
C99 structure initialization in gcc-2.95.3 vs gcc-3.3.1 Kevin P. Fleming C Programming 2 11-06-2003 05:15 AM



Advertisments