[PATCH] C undefined behavior fix

Linus Torvalds torvalds@transmeta.com
Sat Jan 5 10:49:00 GMT 2002


On Sat, 5 Jan 2002, Florian Weimer wrote:
>
> Yes, but you have to read the whole paragraph:

I have, but unlike you, I can actually read.

>        [#6]  Any  pointer type may be converted to an integer type.
>        Except   as   previously   specified,    the    result    is
>        implementation-defined.  If the result cannot be represented
>        in the integer type, the behavior is undefined.  The  result
>        need not be in the range of values of any integer type.
>
> A less verbose version is: "Any pointer type may be converted to an
> integer type, and the behavior is undefined."

That's some interesting language skills you have.

You somehow magically dropped the conditional.

And that conditional is very very important.

Guess what? Gcc has a _warning_ for when the conditional happens. It's
called

	warning: cast from pointer to integer of different size

and it's a warning when you invoce the undefined behaviour rather than the
implementation-defined one.

And people who know what the implementation is (and can read plain
english) know that a 32-bit pointer can be represented perfectly well in a
32-bit integer as on normal architectures.

You not being able to read does not change that fact.

You also do not seem to realize that C is a unique language: it's a
mid-level langauge with a number of fairly high-level features, but it is
also able to do low-level stuff. That was how it was designed, by people
smarter than you or me. And that's exactly WHY the standard notes the
fact that the conversion is supposed to be consistent with the addressing
mode of the machine.

I'm not going to asnwer you idiotic claims any more. Your reading of the
standard has nothing to do with C, the English language, or logic.

			Linus



More information about the Gcc mailing list