This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Avoiding "assignment from incompatible pointer type" warning
>>>>> "Florian" == Florian Weimer <fw@deneb.enyo.de> writes:
Florian> "Joshua Nye" <josh@boxcarmedia.com> writes:
>>> > int *p;
>>> > float g = 3.141592653589793238;
>>> > p = (int *)&g;
>>>
>>> Is this code legal? I doubt it.
>>>
>> What do you consider legal and why wouldn't it be?
Florian> Casting a pointer from float to int can result in
Florian> undefined behavior on some implementations.
I can't see why. Can you elaborate on that? I mean, casting on the
machine code level does just nothing - it's just "syntactic sugar" to
convince the compiler to be quiet. I think casting from one pointer
type to another does no harm at all. Am I wrong?
--
Claudio Bley ASCII ribbon campaign (")
Debian GNU/Linux advocate - against HTML email X
http://www.cs.uni-magdeburg.de/~bley/ & vCards / \