This is the mail archive of the gcc-help@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]

Re: Avoiding "assignment from incompatible pointer type" warning


On Monday 21 October 2002 04:22, Claudio Bley wrote:
> >>>>> "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?

Hello,
I guess that today it doesn't matter. But what is, if the size of the pointers 
differ? You should use 'void*' which can store any pointer.

Bye


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