Author: Dieter Buerssner
Date: 14:42:25 05/11/03
Go up one level in this thread
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.
Not to mention, that there are C-implementations, that don't have 32 bit ints,
that have 32 bit chars and int, etc.
> return 0;
>}
Regards,
Dieter
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.