This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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






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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]