Harald JOHNSEN wrote:
> Is it a gcc 4.0.2 (SuSE 10.0) compiler bug? tiny_xdr.cxx contains
> this function;
>
> dummy = XDR_decode_int32 (f_Val);
> tmp = (float*) &dummy;
> return (*tmp);

This violates the strict aliasing rules that are the default for
gcc 4.x -- I believe it issues a warning to that effect.  (Although
in this case the compiler should be able to detect that the pointer
can never be incorrectly aliased and optimize the warning away). If you
want to type-pun, you need to use a union:

    union { int i; float f; } dummy;
    dummy.i = XDR_decode_int32(f_Val);
    return dummy.f;

The union trick also tends to be a little more readable, IMHO.

Andy

_______________________________________________
Flightgear-devel mailing list
Flightgear-devel@flightgear.org
http://mail.flightgear.org/mailman/listinfo/flightgear-devel
2f585eeea02e2c79d7b1d8c4963bae2d

Reply via email to