anonymous struct members

Discussion in 'C Programming' started by richardw, Oct 23, 2010.

  1. richardw

    richardw Guest

    hi!

    this struct seems to be vaild c99:

    struct foo {
    int:1;
    };


    when makes such a struct sense?
    is the anonymous member used for padding?

    thanks,
    //richard
     
    richardw, Oct 23, 2010
    #1
    1. Advertising

  2. richardw <> writes:

    > this struct seems to be vaild c99:
    >
    > struct foo {
    > int:1;
    > };


    From 6.7.2.1 Structure and union specifiers

    7 The presence of a struct-declaration-list in a struct-or-union-
    specifier declares a new type, within a translation unit. The
    struct-declaration-list is a sequence of declarations for the
    members of the structure or union. If the struct-declaration-
    list contains no named members, the behavior is undefined.

    so "valid" is a debatable description! Paragraph 7 is not a constraint
    so no diagnostic is required, but gcc gives one when invoked in
    conforming mode.

    > when makes such a struct sense?
    > is the anonymous member used for padding?


    I don't think it does make sense, except perhaps as a compiler test
    case.

    --
    Ben.
     
    Ben Bacarisse, Oct 23, 2010
    #2
    1. Advertising

  3. China Blue Police Box <> writes:

    > In article <>,
    > richardw <> wrote:
    >
    >> this struct seems to be vaild c99:
    >>
    >> struct foo {
    >> int:1;
    >> };
    >>
    >>
    >> when makes such a struct sense?
    >> is the anonymous member used for padding?

    >
    > Yes, padding.


    I see you interpreted the question slightly differently. I thought the
    question was about the whole struct (and that's undefined,
    i.e. "invalid").

    Just to be clear, the passage I quoted relates to the whole struct;
    unnamed bit-fields are permitted provided there are some named members
    in the struct.

    <snip>
    --
    Ben.
     
    Ben Bacarisse, Oct 23, 2010
    #3
    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. mark fine
    Replies:
    1
    Views:
    487
    Michael Jørgensen
    Nov 9, 2004
  2. Chris Fogelklou
    Replies:
    36
    Views:
    1,444
    Chris Fogelklou
    Apr 20, 2004
  3. Reporter
    Replies:
    3
    Views:
    498
    Mike Schilling
    May 12, 2007
  4. Replies:
    1
    Views:
    241
  5. John Reye
    Replies:
    28
    Views:
    1,416
    Tim Rentsch
    May 8, 2012
Loading...

Share This Page