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
"Claudio Bley" <bley@cs.uni-magdeburg.de> writes:
> >> 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?
Well, it's all in the standard, although it's a bit scattered.
> I mean, casting on the machine code level does just nothing - it's
> just "syntactic sugar" to convince the compiler to be quiet.
It's not. In C, pointers are NOT machine addresses. Pointers are an
abstract concept, and often, something which would work if they were
machine addresses, fails miserably. For example, even if two pointers
compare equal (because they point to the same object), it's possible
that an operation on one of the two is undefined, while it is defined
for the other one.
> I think casting from one pointer type to another does no harm at
> all. Am I wrong?
Yes, you are, I'm afraid.