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


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.


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