Unnamed union

Discussion in 'C Programming' started by Frank Roland, Oct 13, 2003.

  1. Frank Roland

    Frank Roland Guest

    I know it is possible to use unnamed struct or unions inside of struct like
    in the following example:

    typedef struct {
    union {
    int moin;
    char carl;
    };
    int bon;
    } dastruct;

    int main(int argc, char * argv[])
    {
    dastruct thestruct;

    thestruct.carl = 'a';
    thestruct.bon=6;
    ...


    Now I have a compiler which does not allow me to acces moin or carl unless I
    give the union a name, like here:

    typedef struct {
    union {
    int moin;
    char carl;
    } x;
    int bon;
    } dastruct;


    int main(int argc, char * argv[])
    {
    dastruct thestruct;

    thestruct.x.carl = 'a';
    thestruct.bon=6;
    ....


    What I wonder is, wheter unnamed struct and unions are a feature of newer C
    standard (C99)?

    Kind regards,
    Frank
     
    Frank Roland, Oct 13, 2003
    #1
    1. Advertising

  2. Frank Roland

    Eric Sosman Guest

    Frank Roland wrote:
    >
    > I know it is possible to use unnamed struct or unions inside of struct like
    > in the following example:
    >
    > typedef struct {
    > union {
    > int moin;
    > char carl;
    > };
    > int bon;
    > } dastruct;


    I know that the Earth is flat, that the Moon is made of
    green cheese, and that the stuff advertised in all those
    E-mails really will make my member grow larger.

    > What I wonder is, wheter unnamed struct and unions are a feature of newer C
    > standard (C99)?


    No, and this is not a change: No C Standard has permitted
    nameless elements in structs, with the exception of a special
    case involving bit-fields. Various compilers have supported
    this as an extension to the C language, but it has always
    been an extension.

    --
     
    Eric Sosman, Oct 13, 2003
    #2
    1. Advertising

  3. Greetings.

    In article <bmeter$jui$00$-online.com>, Frank Roland wrote:
    > What I wonder is, wheter unnamed struct and unions are a feature of newer
    > C standard (C99)?


    I asked this back in message <> -- the answer
    is no, C99 does not support anonymous unions. Pity, as they are supported
    in C++, and I actually use them from time to time.

    Regards,
    Tristan

    --
    _
    _V.-o Tristan Miller [en,(fr,de,ia)] >< Space is limited
    / |`-' -=-=-=-=-=-=-=-=-=-=-=-=-=-=-= <> In a haiku, so it's hard
    (7_\\ http://www.nothingisreal.com/ >< To finish what you
     
    Tristan Miller, Oct 14, 2003
    #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. Mattia Belletti

    unnamed object creation

    Mattia Belletti, Oct 20, 2003, in forum: Java
    Replies:
    4
    Views:
    430
    Jason Us
    Oct 22, 2003
  2. Matt Garman
    Replies:
    1
    Views:
    669
    Matt Garman
    Apr 25, 2004
  3. Mysooru

    Unnamed "Formal Parameter"

    Mysooru, Jul 24, 2003, in forum: C++
    Replies:
    3
    Views:
    454
    Mike Wahler
    Jul 24, 2003
  4. Razmig K
    Replies:
    3
    Views:
    689
    John L Fjellstad
    Sep 5, 2003
  5. Peter Dunker

    union in struct without union name

    Peter Dunker, Apr 26, 2004, in forum: C Programming
    Replies:
    2
    Views:
    875
    Chris Torek
    Apr 26, 2004
Loading...

Share This Page