Avoiding "assignment from incompatible pointer type" warning

Florian Weimer fw@deneb.enyo.de
Mon Oct 21 06:52:00 GMT 2002

John Love-Jensen <eljay@adobe.com> writes:

>> 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?
> You are correct, the casting is fine, insofar as the given code snippet
> goes.
> I assume the complaint/concern was regarding the (presumed)
> dereferencing of the int* p at some later point in the code.

Oh, please.  An implementation is free to consider such pointer
conversions to be undefined (of course, an implementation may do
something useful nevertheless), so it's essentially undefined.  And
the undefined behavior is triggered upon the cast, not when the
pointer is dereferenced. only ensures that conforming implementations may not issue
a diagnostic for such programming errors.

More information about the Gcc-help mailing list