Date: Mon, 5 Aug 2002 09:09:17 +0100 From: Matthew Seaman <m.seaman@infracaninophile.co.uk> To: "Balaji, Pavan" <pavan.balaji@intel.com> Cc: "'freebsd-questions@freebsd.org'" <freebsd-questions@FreeBSD.ORG> Subject: Re: GCC versions!!! Message-ID: <20020805080917.GB15513@happy-idiot-talk.infracaninophi> In-Reply-To: <3D386AED1B47D411A94300508B11F18704AD6999@fmsmsx116.fm.intel.com> References: <3D386AED1B47D411A94300508B11F18704AD6999@fmsmsx116.fm.intel.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, Aug 04, 2002 at 07:09:16PM -0700, Balaji, Pavan wrote:
>
> I ran this program on FreeBSD (GCC version 2.95.3) and the output for this
> program was
> 1 256 65536 0
>
> I reran it on Linux (GCC version 3.0.something) and the output was:
> 16777216 65536 1 0 (as expected).
>
> After a little poking around, I could figure out that the memory for the
> structure was allocated in a way that for every word boundary, the bytes
> allocation is in the reverse order. For example, if I have 4 characters in a
> structure a, b, c and d, the memory for d is allocated first, then c, then b
> and finally a.
>
> Is this something to do with gcc or with freebsd? Any ideas?
I get exactly the same output with the standard gcc-2.95.4 and with
gcc-3.1.1 from ports:
happy-idiot-talk:/tmp:% cc -v
Using builtin specs.
gcc version 2.95.4 20020320 [FreeBSD]
happy-idiot-talk:/tmp:% cc -o foo-2.95.4 foo.c
[...]
happy-idiot-talk:/tmp:% ./foo-2.95.4
1 256 65536 0
happy-idiot-talk:/tmp:% gcc31 -v
[...]
gcc version 3.1.1 [FreeBSD]
happy-idiot-talk:/tmp:% gcc31 -o foo-3.1.1 foo.c
[...]
happy-idiot-talk:/tmp:% ./foo-3.1.1
1 256 65536 0
I doubt there's a difference at this level between gcc on Linux or
FreeBSD: this sort of alignment/endianness issue is mostly a function
of the CPU the code is running on. At a guess, your second result was
obtained on a Sparc or PowerPC[*] or similar CPU, which is the
other-endian from an x86 class CPU: I never can rememder which one is
'big-endian' and which one is 'little-endian' though.
Matthew
[*] PowerPC can work 'either-endian' but I thing most Unix OS's select
this way.
--
Dr Matthew J Seaman MA, D.Phil. 26 The Paddocks
Savill Way
Tel: +44 1628 476614 Marlow
Fax: +44 0870 0522645 Bucks., SL7 1TH UK
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020805080917.GB15513>
