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

Purnendu/Gmail purnendu@gmail.com
Fri Oct 15 15:53:00 GMT 2004


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.



More information about the Gcc-help mailing list