public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Deepen Mantri" <Deepen.Mantri@kpitcummins.com>
To: <gcc-help@gcc.gnu.org>
Cc: <panruochen@gmail.com>
Subject: Re: how to initialize union?
Date: Mon, 24 Mar 2008 08:48:00 -0000	[thread overview]
Message-ID: <78DE440C4156CC45A35FDBCBF9B830D70241D51D@sohm.kpit.com> (raw)

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

             reply	other threads:[~2008-03-24  8:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-24  8:48 Deepen Mantri [this message]
  -- strict thread matches above, loose matches on Subject: below --
2008-03-27  7:35 Eus
2008-03-22 13:11 PRC

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=78DE440C4156CC45A35FDBCBF9B830D70241D51D@sohm.kpit.com \
    --to=deepen.mantri@kpitcummins.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=panruochen@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).