Re: how to initialize union?

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

 



>>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?


The union variable can be initialized with the help of,
union my_union B = {.v = {'a',16,NULL}};


Regards,
Deepen Mantri
KPIT Cummins InfoSystems Ltd.
Pune, India

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Free download of GNU based tool-chains for Renesas' SH, H8, R8C, M16C
and M32C Series. The following site also offers free technical support
to its users. Visit http://www.kpitgnutools.com for details.
Latest versions of KPIT GNU tools were released on February 4, 2008
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


[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