C99 struct initialization (C99/gcc)

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

  1. Guest

    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.
     
    , Feb 5, 2006
    #1
    1. Advertising

  2. 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
    #2
    1. Advertising

  3. Abhishek Guest

    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
    #3
  4. Chris Torek Guest

    (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:
    >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.
     
    Chris Torek, Feb 20, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peng Yu
    Replies:
    2
    Views:
    734
    Default User
    Sep 29, 2004
  2. Kevin P. Fleming

    C99 structure initialization in gcc-2.95.3 vs gcc-3.3.1

    Kevin P. Fleming, Nov 6, 2003, in forum: C Programming
    Replies:
    2
    Views:
    662
    Kevin P. Fleming
    Nov 6, 2003
  3. Chris Fogelklou
    Replies:
    36
    Views:
    1,430
    Chris Fogelklou
    Apr 20, 2004
  4. Replies:
    2
    Views:
    758
    David Harmon
    Sep 20, 2006
  5. Replies:
    3
    Views:
    619
    Keith Thompson
    Mar 31, 2007
Loading...

Share This Page