This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/20709] strict aliasing warning with float pointer pointing to int pointer
- From: "segher at kernel dot crashing dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 5 Apr 2005 23:32:11 -0000
- Subject: [Bug c/20709] strict aliasing warning with float pointer pointing to int pointer
- References: <20050401054311.20709.varun0005@gmail.com>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From segher at kernel dot crashing dot org 2005-04-05 23:32 -------
Subject: Re: strict aliasing warning with float pointer pointing to int pointer
> Aka this is valid and defined (even though we warn):
> float a(float b)
> {
> int i;
> *(float*)&i = b;
> return *(float*)&i;
> }
Here, you access the object 'i' of type int, as an object of type
float. This is not allowed; see 6.5/7.
Perhaps you meant something like:
int a;
float *f(void)
{
return (float *)&a;
}
int g(void)
{
return *(int *)f();
}
which is fine, but we indeed warn.
Note it doesn't matter for the validity of this code that float
fits in the same object as int; it is important that float * can
represent the address of an int, though (6.3.2.3/7).
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20709