This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Strict aliasing and converting binary patterns between integer and float
- From: Olivier Galibert <galibert at pobox dot com>
- To: gcc at gcc dot gnu dot org
- Date: Sun, 31 Aug 2003 23:44:30 +0200
- Subject: Strict aliasing and converting binary patterns between integer and float
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). Up until now I've been using the usual:
unsigned int f(void);
float g(void)
{
unsigned int v1;
float v2;
v1 = f();
v2 = *(float *)&v1;
return v2;
}
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?
OG.