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
- From: Florian Weimer <fw at deneb dot enyo dot de>
- To: John Love-Jensen <eljay at adobe dot com>
- Cc: Claudio Bley <bley at cs dot uni-magdeburg dot de>, Joshua Nye <josh at boxcarmedia dot com>, Steve Dondley <s at dondley dot com>, <gcc-help at gcc dot gnu dot org>
- Date: Mon, 21 Oct 2002 15:52:06 +0200
- Subject: Re: Avoiding "assignment from incompatible pointer type" warning
- References: <B9D96E10.5411%eljay@adobe.com>
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.
6.3.2.3(7) only ensures that conforming implementations may not issue
a diagnostic for such programming errors.