Bug Report
Tuukka Tikkanen
tic0@teraflops.com
Wed May 23 13:07:00 GMT 2001
> I was surprised by the result of this simple program compiling with gcc
> 2.95 on Red Hat Linux 7.0.
> Could you check whether is it a bug of gcc 2.95 (for Red Hat Linux 7.0)?
You are forgetting the endianess of x86 processors. The behaviour is exactly
correct (ie. the numbers are printed in reverse order) for intel-based
system whereas you will (and should) get different result on for example
motorola 68000-based system.
If you need to write code that is portable (and if you need to play with
byte order) you should either use htonl(),htons(),ntohl(),ntohs() macros or
#include endian.h and use the __BYTE_ORDER, __BIG_ENDIAN and __LITTLE_ENDIAN
definitions.
Tuukka
More information about the Gcc-bugs
mailing list