From: "Randy.Dunlap" Subject: Re: code explaination Date: Thu, 18 Sep 2003 23:54:54 -0700 Sender: linux-fsdevel-owner@vger.kernel.org Message-ID: <20030918235454.54b7fccf.rddunlap@osdl.org> References: <20030919052139.3375.qmail@webmail26.rediffmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: hbryan@us.ibm.com, linux-fsdevel@vger.kernel.org Return-path: Received: from fw.osdl.org ([65.172.181.6]:30956 "EHLO mail.osdl.org") by vger.kernel.org with ESMTP id S261368AbTISG5y (ORCPT ); Fri, 19 Sep 2003 02:57:54 -0400 To: "vadiraj c s" In-Reply-To: <20030919052139.3375.qmail@webmail26.rediffmail.com> List-Id: linux-fsdevel.vger.kernel.org On 19 Sep 2003 05:21:39 -0000 "vadiraj c s" wrote: | On Thu, 18 Sep 2003 Bryan Henderson wrote : | > >On x86, which is little endian, this will contain | > >the value 100 (0x64). On a big endian machine this will be | >zero. When you | > >access pqr.i = 300, the lowest byte will be 44 (0x2c) on little | >endian and zero on big endian. | > | >That doesn't explain the behavior he asked about: | > | > >> output: | > >> char abc 0 | > >> int abc 300; | > >> swap the structure value to i=300,j = 100; | > >> you get | > >> char abc 1; | > | >(i.e. the values are 0 and 1, not 100 and 44 or 0 and 0). | > | >Not only that, the "int abc 300" line is inconsistent with the | >program | >posted, and the program posted won't even compile because there's | >a typo in the name of the abc_int() definition. | > | >It looks like there's a lot of reason to believe that there is | >just an experimental error here. | > | > > #include | > > struct xyz{ | > > | > > int i; | > > int j; | > > } pqr = {100,300} ; | > > int main() | > > { | > > struct xyz *z ; | z = &pqr; | > > abc_char(z); | > > abc_int(z) ; | > > } | > > | > > void abc_char(char *i) | > > { | > > printf("char abc %d",*i) ; | > > } | > > | > > void abc_int(int *i) | > > { | > > printf("int abc %d",*i) ; | > > } | | I apologize for the syntax mistake, as you said it does not | explain the behavior of the code.... I knew the output to be as he | explained, but it din't whats the reason... | | it was executed on x86 machine on linux platform, where size of | int is 4 bytes... | | //vadiraj ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Is this cleared up now? (other than being the wrong m-l?) If i is 100, I get (as expected on little-endian x86): char abc 100 int abc 100 If i is 300, I get (as expected on little-endian x86): char abc 44 int abc 300 -- ~Randy