Author: Gareth McCaughan
Date: 16:26:49 05/11/03
Go up one level in this thread
On May 11, 2003 at 17:42:25, Dieter Buerssner wrote:
> On May 11, 2003 at 17:24:41, Gareth McCaughan wrote:
>
>> $ cat endian.c
>> #include <stdio.h>
>> int main(void) {
>> union { struct { char a,b,c,d; }; int i; } x;
>> x.i = 0x01020304;
>> printf("%d %d\n", x.a, x.b);
>
> Gareth, I mostly agree with what you said. But it is even more severe. The last
> line is undefined behaviour. In Standard C, you can not fetch a member out of a
> union, other than the last one stored.
The program wasn't meant to be legal. Just to demonstrate that,
as a matter of fact, the order on ia32 is LSB-first, not MSB-first.
> Not to mention, that there are C-implementations, that don't have 32 bit ints,
> that have 32 bit chars and int, etc.
Indeed.
--
g
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.