Re: how to initialize union?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



PRC wrote:

> union my_union {
>   struct {
>     int a;
>     int b;
>   };
>   struct {
>     char a;
>     short b;
>     void *c;
>   } v;
> };
>
> And I want to initialize 2 global variables, of `my_union' type, A and B to:
> ------------------------------------
> A.a=1; A.b=2;
> B.v.a='a'; B.v.b=16; B.v.c=NULL;
> ------------------------------------
> I know how to initialize A by:
> union my_union A = { 1, 2 };
>
> But I don't know how to write the initializers for B.
> Can gcc support this feature?

union my_union B = {
        .v.a = 'a',
        .v.b = 16,
        .v.c = NULL
};

will do the job.

Best regards,
Eus (FSF member #4445)

In this digital era, where computing technology is pervasive, your freedom depends on the software controlling those computing devices.

Join free software movement today!
It is free as in freedom, _NOT_ as in free beer!
Use the following link to join:
http://www.fsf.org/register_form?referrer=4445

For more information, visit the following links:
- Free Software, Free Society
http://www.gnu.org/philosophy/fsfs/rms-essays.pdf
- The GNU Project
http://gnu.org
- The Free Software Foundation
http://fsf.org


      ____________________________________________________________________________________
Never miss a thing.  Make Yahoo your home page. 
http://www.yahoo.com/r/hs

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux