From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27618 invoked by alias); 15 Oct 2004 15:53:10 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 27611 invoked from network); 15 Oct 2004 15:53:09 -0000 Received: from unknown (HELO mproxy.gmail.com) (64.233.170.196) by sourceware.org with SMTP; 15 Oct 2004 15:53:09 -0000 DomainKey-Signature: a=rsa-sha1; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:references; b=TDhEDEzdMa5e4hDYvNtpR/9mxiEfvtBbrJtm5eXwQuEihd2CO9ksUiioL8ixomrAeD5TQNtyyqMcc8xDh7cUr1kmtrguoCr18M6MDOv+T/q36KBdh51fTld1rmBwJPtdq4Fm7mnLuii5ms5Q45qhVFJb2mN+TqOdu/i6aVRaaSc Received: by mproxy.gmail.com with SMTP id 74so41583rnk for ; Fri, 15 Oct 2004 08:53:09 -0700 (PDT) Received: by 10.39.1.26 with SMTP id d26mr296398rni; Fri, 15 Oct 2004 08:52:39 -0700 (PDT) Received: by 10.38.181.34 with HTTP; Fri, 15 Oct 2004 08:52:39 -0700 (PDT) Message-ID: <4ca029ac04101508526859c816@mail.gmail.com> Date: Fri, 15 Oct 2004 15:53:00 -0000 From: Purnendu/Gmail Reply-To: Purnendu/Gmail To: "Kelly, Fergal" Subject: Re: FW: two sturtures in a union.... -- corrected mistakes Cc: gcc-help@gcc.gnu.org In-Reply-To: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit References: X-SW-Source: 2004-10/txt/msg00110.txt.bz2 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 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.