This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/20709] strict aliasing warning with float pointer pointing to int pointer


------- 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]