RE: FW: two sturtures in a union.... -- corrected mistakes

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

 



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@xxxxxxxxx]
Sent: 15 October 2004 16:53
To: Kelly, Fergal
Cc: gcc-help@xxxxxxxxxxx
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@xxxxxxxxxxxxxx> 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.


[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