* Re: how to initialize union?
@ 2008-03-27 7:35 Eus
0 siblings, 0 replies; 3+ messages in thread
From: Eus @ 2008-03-27 7:35 UTC (permalink / raw)
To: PRC; +Cc: gcc-help
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: how to initialize union?
@ 2008-03-24 8:48 Deepen Mantri
0 siblings, 0 replies; 3+ messages in thread
From: Deepen Mantri @ 2008-03-24 8:48 UTC (permalink / raw)
To: gcc-help; +Cc: panruochen
>>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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
^ permalink raw reply [flat|nested] 3+ messages in thread
* how to initialize union?
@ 2008-03-22 13:11 PRC
0 siblings, 0 replies; 3+ messages in thread
From: PRC @ 2008-03-22 13:11 UTC (permalink / raw)
To: gcc-help
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?
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-03-27 7:35 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-27 7:35 how to initialize union? Eus
-- strict thread matches above, loose matches on Subject: below --
2008-03-24 8:48 Deepen Mantri
2008-03-22 13:11 PRC
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).