[EMAIL PROTECTED] writes: > On Mon, Jun 12, 2006 at 12:30:50PM +0000, [EMAIL PROTECTED] wrote: > > On Mon, Jun 12, 2006 at 02:21:21PM +0200, Richard Guenther wrote: > > > On 6/12/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > > >On Mon, Jun 12, 2006 at 01:01:47PM +0100, Andrew Haley wrote: > > > >> > > > >> I'm starting to be a little suspicious about host2little(). I wonder > > > >> if that's well-defined. > > > >> > > > >> I'm just guessing here becasue I can't see the code. Is it possible > > > > > > > > template<typename T> T swap_endian(T x) > > > > { > > > > char* a = reinterpret_cast<char*>(&x); > > > > char* b = a + sizeof(T) - 1; > > > > while (a<b) { > > > > char tmp = *a; > > > > *a++ = *b; > > > > *b-- = tmp; > > > > } > > > > return x; > > > > } > > > > > > > > template<typename T> T host2little(T x) > > > > { > > > > unsigned u = 1; return (*reinterpret_cast<char*>(&u) ? x : > > > > swap_endian(x)); > > > > } > > > > > > You are violating aliasing rules. Try -fno-strict-aliasing, which > > > should make the code > > > work, or fix it. > > > > Hmmm - don't grok; I'll do some googling. Compiling now with > > -fno-strict-aliasing, but the manual says -O2 includes > > -strict-aliasing, so what gives? > > Indeed, -fno-strict-aliasing makes no difference; its still broken. Well, that is interesting! I think both Richard Guenther and I both thought you had an aliasing problem somewhere: all those pointer casts are something of a red flag...
OK, well, we're stuck until you can make a test case. Andrew.