Re: [PATCH][RESEND] do not redefine userspace's NULL #define

From: Linus Torvalds
Date: Fri Apr 13 2012 - 18:24:25 EST


On Fri, Apr 13, 2012 at 3:01 PM, Peter Seebach
<peter.seebach@xxxxxxxxxxxxx> wrote:
>
> I was going to dispute this, and point out that I'm pretty sure
> the C++ standard specifically requires the plain-integer 0/0L
> definition.  Then I realized this did not actually contradict
> your description.

Yeah, the C++ definition i spure crap. Although I think even the worst
C++ people realized that, and realized that they were wrong. So most
of them seem to have figured out that defining NULL to 0 is insane and
totally wrong.

(IOW, if you don't get a warning for

int i = NULL;

or get a warning for passing NULL to a routine that takes "int", your
language is pure and utter sh*t. Yes, K&R C made that mistake too, but
it got fixed. The fact that the C++ people used to *codify* that
insane braindamage is just sad).

> Maybe the thing to do would be to ensure that NULL goes to __null,
> then define that to be ((void *) 0) if the compiler doesn't provide
> it?  The magic behavior of __null seems like it'd be preferable
> where it is available.

So if gcc guarantees that __null has the correct semantics, I could
imagine replacing the kernel ((void *)0) with __null.

But unless we *know* that the incoming NULL is good, there's no way I
will let the kernel ever make the mistake of taking '0'.

Linus
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/