public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Kelly, Fergal" <F.Kelly@emuse-tech.com>
To: "Purnendu/Gmail" <purnendu@gmail.com>
Cc: <gcc-help@gcc.gnu.org>
Subject: RE: FW: two sturtures in a union.... -- corrected mistakes
Date: Mon, 18 Oct 2004 15:35:00 -0000	[thread overview]
Message-ID: <EDC1AD47B89E3C42A81DCBC262C5827B1B8AD1@nohassle.emuse.ie> (raw)

Thanks for your help.

I got it to work by changing the order of 

> > typedef union _union
> > {
> >       struct1 one;            /* Index for list value */
> >       char* mpChar            /* Value as a string */
> >       int mID1                                /* Value as an image identifier */
> >       int mID2                                /* Index for relative value */
> >       struct2 two;                                    /* Value as an Integer */
> > }union

to the following


> > typedef union _union
> > {
> >       struct2 two;   
> >       struct1 one;    
> >       char* mpChar;
> >       int mID1;
> >       int mID2;
> > }union

-----Original Message-----
From: Purnendu/Gmail [mailto:purnendu@gmail.com]
Sent: 15 October 2004 16:53
To: Kelly, Fergal
Cc: gcc-help@gcc.gnu.org
Subject: Re: FW: two sturtures in a union.... -- corrected mistakes


yes kelly there  is an order.
it all depends upon the order of assigning value to the members of the union.
if u have assigned value to "struct2 two" at the end then only it will
contain the value for future references.



On Fri, 15 Oct 2004 16:38:33 +0100, Kelly, Fergal
<f.kelly@emuse-tech.com> wrote:
> 
> 
> > Hi, I've the following problem...
> >
> > This is the relevant code, problem below....
> >
> >
> > typedef struct _struct1
> > {
> >     int mHigherWord;
> >     unsigned int mLowerWord;
> > }struct1
> >
> >
> > typedef struct _struct2
> > {
> >       short mInt1;
> >       int mInt2;
> >       short mInt3;
> > }struct2;
> >
> >
> > typedef union _union
> > {
> >       struct1 one;            /* Index for list value */
> >       char* mpChar            /* Value as a string */
> >       int mID1                                /* Value as an image identifier */
> >       int mID2                                /* Index for relative value */
> >       struct2 two;                                    /* Value as an Integer */
> > }union
> >
> >
> > typedef struct _struct3
> > {
> >    enum1 enumfirst;
> >     union union1
> >     enum2 enum2nd;
> >     struct1 notrelevant;
> >     enum1 enumthird;
> >     union union2;
> >  }struct3;
> >
> >
> > Basically when I try to access a struct.union2.two i.e. the second struct in the union, it doesn't return the correct data for the value mInt3, it thinks the structure is of type union1 and only deals with the first two entries.....
> >
> > Is there an issue with have two structures in a union which are the same size???  Is there a particular order which everything needs to be defined in.
> >
> > Any help would be most appreciated.
> >
> > Regards,
> >
> > Fergal
> >
> >
> 


-- 
Gravitation is not responsible for people falling in love.

             reply	other threads:[~2004-10-18 15:35 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-10-18 15:35 Kelly, Fergal [this message]
  -- strict thread matches above, loose matches on Subject: below --
2004-10-18 15:34 Kelly, Fergal
2004-10-15 15:39 Kelly, Fergal
2004-10-15 15:53 ` Purnendu/Gmail

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=EDC1AD47B89E3C42A81DCBC262C5827B1B8AD1@nohassle.emuse.ie \
    --to=f.kelly@emuse-tech.com \
    --cc=gcc-help@gcc.gnu.org \
    --cc=purnendu@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).