Strict aliasing and converting binary patterns between integer and float

Richard Kenner kenner@vlsi1.ultra.nyu.edu
Mon Sep 1 03:23:00 GMT 2003


    I need to convert back and forth between an unsigned int and the float
    with the same binary pattern (admitting I knows they're the same size
    - 32bits - in the first place).  

    WHile this very simple example may still work with -fstrict-aliasing,
    as soon as you have a more complex function the value of v2 is not
    always what is expected.

    So my question is, what is a reliable way to do this conversion with
    gcc and strict aliasing enabled?

Use a union.



More information about the Gcc mailing list