public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* RE: FW: two sturtures in a union.... -- corrected mistakes
@ 2004-10-18 15:35 Kelly, Fergal
  0 siblings, 0 replies; 4+ messages in thread
From: Kelly, Fergal @ 2004-10-18 15:35 UTC (permalink / raw)
  To: Purnendu/Gmail; +Cc: gcc-help

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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: FW: two sturtures in a union.... -- corrected mistakes
@ 2004-10-18 15:34 Kelly, Fergal
  0 siblings, 0 replies; 4+ messages in thread
From: Kelly, Fergal @ 2004-10-18 15:34 UTC (permalink / raw)
  To: Purnendu/Gmail; +Cc: gcc-help


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

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: FW: two sturtures in a union.... -- corrected mistakes
  2004-10-15 15:39 Kelly, Fergal
@ 2004-10-15 15:53 ` Purnendu/Gmail
  0 siblings, 0 replies; 4+ messages in thread
From: Purnendu/Gmail @ 2004-10-15 15:53 UTC (permalink / raw)
  To: Kelly, Fergal; +Cc: gcc-help

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.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* FW: two sturtures in a union....  -- corrected mistakes
@ 2004-10-15 15:39 Kelly, Fergal
  2004-10-15 15:53 ` Purnendu/Gmail
  0 siblings, 1 reply; 4+ messages in thread
From: Kelly, Fergal @ 2004-10-15 15:39 UTC (permalink / raw)
  To: gcc-help






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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2004-10-18 15:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-18 15:35 FW: two sturtures in a union.... -- corrected mistakes Kelly, Fergal
  -- 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

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