* Melchior FRANZ -- Friday 02 December 2005 01:43: > But ... we weren't really returning the address of an auto var.
Is it a gcc 4.0.2 (SuSE 10.0) compiler bug? tiny_xdr.cxx contains this function; float XDR_decode_float ( const xdr_data_t & f_Val ) { float* tmp; xdr_data_t dummy; dummy = XDR_decode_int32 (f_Val); tmp = (float*) &dummy; return (*tmp); } And it turned out that when compiled with gcc 4.0.2 the return value wasn't safe. When called three times in a row with different values, we would get three times the same result. None of those correct. This placed MP aircraft somewhere around the middle of our Earth. For those understanding x86 assembler, here is the resulting code (why does it not call _Z16XDR_decode_int32RKj? "Optimized" away?): non-static "dummy" (-O2) --> doesn't work (gdb) disass XDR_decode_float Dump of assembler code for function _Z16XDR_decode_floatRKj: 0x08310816 <_Z16XDR_decode_floatRKj+0>: push %ebp 0x08310817 <_Z16XDR_decode_floatRKj+1>: mov %esp,%ebp 0x08310819 <_Z16XDR_decode_floatRKj+3>: sub $0x10,%esp 0x0831081c <_Z16XDR_decode_floatRKj+6>: flds 0xfffffffc(%ebp) 0x0831081f <_Z16XDR_decode_floatRKj+9>: leave 0x08310820 <_Z16XDR_decode_floatRKj+10>: ret End of assembler dump. The following was compiled without optimization. The resulting code works. non-static "dummy" (-O0) --> works (gdb) disass XDR_decode_float Dump of assembler code for function _Z16XDR_decode_floatRKj: 0x083be33a <_Z16XDR_decode_floatRKj+0>: push %ebp 0x083be33b <_Z16XDR_decode_floatRKj+1>: mov %esp,%ebp 0x083be33d <_Z16XDR_decode_floatRKj+3>: sub $0x18,%esp 0x083be340 <_Z16XDR_decode_floatRKj+6>: mov 0x8(%ebp),%eax 0x083be343 <_Z16XDR_decode_floatRKj+9>: mov %eax,(%esp) 0x083be346 <_Z16XDR_decode_floatRKj+12>: call 0x83be1b4 <_Z16XDR_decode_int32RKj> 0x083be34b <_Z16XDR_decode_floatRKj+17>: mov %eax,0xfffffff8(%ebp) 0x083be34e <_Z16XDR_decode_floatRKj+20>: lea 0xfffffff8(%ebp),%eax 0x083be351 <_Z16XDR_decode_floatRKj+23>: mov %eax,0xfffffffc(%ebp) 0x083be354 <_Z16XDR_decode_floatRKj+26>: mov 0xfffffffc(%ebp),%eax 0x083be357 <_Z16XDR_decode_floatRKj+29>: mov (%eax),%eax 0x083be359 <_Z16XDR_decode_floatRKj+31>: mov %eax,0xffffffec(%ebp) 0x083be35c <_Z16XDR_decode_floatRKj+34>: flds 0xffffffec(%ebp) 0x083be35f <_Z16XDR_decode_floatRKj+37>: leave 0x083be360 <_Z16XDR_decode_floatRKj+38>: ret End of assembler dump. and this hack (committed to cvs) works with and without optimization. Making "dummy" static shouldn't be necessary, but static "dummy" --> works (gdb) disass XDR_decode_float Dump of assembler code for function _Z16XDR_decode_floatRKj: 0x08310816 <_Z16XDR_decode_floatRKj+0>: push %ebp 0x08310817 <_Z16XDR_decode_floatRKj+1>: mov %esp,%ebp 0x08310819 <_Z16XDR_decode_floatRKj+3>: sub $0x4,%esp 0x0831081c <_Z16XDR_decode_floatRKj+6>: mov 0x8(%ebp),%eax 0x0831081f <_Z16XDR_decode_floatRKj+9>: mov %eax,(%esp) 0x08310822 <_Z16XDR_decode_floatRKj+12>: call 0x83107e2 <_Z16XDR_decode_int32RKj> 0x08310827 <_Z16XDR_decode_floatRKj+17>: mov %eax,0x8560e00 0x0831082c <_Z16XDR_decode_floatRKj+22>: flds 0x8560e00 0x08310832 <_Z16XDR_decode_floatRKj+28>: leave 0x08310833 <_Z16XDR_decode_floatRKj+29>: ret End of assembler dump. clueless m. _______________________________________________ Flightgear-devel mailing list Flightgear-devel@flightgear.org http://mail.flightgear.org/mailman/listinfo/flightgear-devel 2f585eeea02e2c79d7b1d8c4963bae2d