A
Aaron Graham
Gianni said:I changed it to:
bool tell_endian()
{
unsigned x = 1;
return *(char*)&x;
}
g++ 3.4.2 produces:
00000000 <_Z11tell_endianv>:
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: b8 01 00 00 00 mov $0x1,%eax
8: c9 leave
9: c3 ret
g++ 4.0.0 produces:
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: 83 ec 10 sub $0x10,%esp
6: c7 45 fc 01 00 00 00 movl $0x1,0xfffffffc(%ebp)
d: 31 c0 xor %eax,%eax
f: 80 7d fc 00 cmpb $0x0,0xfffffffc(%ebp)
13: 0f 95 c0 setne %al
16: c9 leave
17: c3 ret
compile line:
g++ -O3 -c -o endian_test.o endian_test.cpp
Seem like a serious optimizer regression to me.
With g++ 3.4.2 it appears that it creates the right code even on -O1
level optimization.
I submitted a bug report at gcc bugzilla, #26069. I used your example,
since all my non-4.0.2 compilers are for different architectures.
Aaron