mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Lubos Lunak <l.lunak@suse.cz>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Seebach <peter.seebach@windriver.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-kernel@vger.kernel.org, Arnd Bergmann <arnd@arndb.de>
Subject: Re: [PATCH][RESEND] do not redefine userspace's NULL #define
Date: Sat, 14 Apr 2012 08:43:08 +0200	[thread overview]
Message-ID: <201204140843.08671.l.lunak@suse.cz> (raw)
In-Reply-To: <CA+55aFzWiaXYSwO7eGt_V6oUZGWkp_v1hv9xc6KAiFnrzumxXA@mail.gmail.com>

On Saturday 14 of April 2012, Linus Torvalds wrote:
> On Fri, Apr 13, 2012 at 4:18 PM, Lubos Lunak <l.lunak@suse.cz> wrote:
> >> imagine replacing the kernel ((void *)0) with __null.
> >
> >  __null apparently exists only with g++, C does not have the stronger
> > type safety that prevents ((void*)0) from being usable in C++
>
> Please don't continue to spread this total bogosity.
>
> The reason C++ cannot use "(void *)0" has nothing to do with "stronger
> type safety". That's a total idiotic lie by C++ apologists, and I hate
> hearing it repeated over and over again.
>
> And it really *is* a lie. The C++ type system isn't even "stronger",

$ cat b.c
void foo()
    {
    int* a;
    void* b;
    char c;
    a = b = &c;
    }
$ gcc -Wall b.c -c
$ g++ -Wall b.c -c
b.c: In function ‘void foo()’:
b.c:6:14: error: invalid conversion from ‘void*’ to ‘int*’

> it's just different, and it's actively *broken* wrt NULL. Always has
> been.
>
> The sane thing to do for C++ would always have been to recognize that
> "(void *)0" is not a "void pointer" - it's just NULL.

 As much as I agree that it was stupid to copy the special-casing of 0 from C 
and they should have instead special-cased (void*)0, the reality is that it 
took them until C++11 to add that to the standard, and even there they did it 
differently, so C++ now has to live with the legacy of NULL being possibly 
implemented in a stupid way.

 The reality is also that g++ people recognized this quite some time back, 
implemented NULL in a sane way, and kernel headers still replace that 
implementation with one that, as you yourself say, is technically wrong. So 
how about my patch that fixes that? The rest is a discussion about things 
that should have been but are not and is completely pointless by now.

8<-----
headers: do not redefine userspace's NULL #define when compiling C++ code

GCC's NULL is actually __null when compiling C++, which allows detecting some
questionable NULL usage and warn about it.

Signed-off-by: Luboš Luňák <l.lunak@suse.cz>
---
 include/linux/stddef.h |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/include/linux/stddef.h b/include/linux/stddef.h
index 6a40c76..a75f4b9 100644
--- a/include/linux/stddef.h
+++ b/include/linux/stddef.h
@@ -3,12 +3,18 @@
 
 #include <linux/compiler.h>
 
-#undef NULL
 #if defined(__cplusplus)
-#define NULL 0
+#ifndef NULL
+#ifdef __GNUG__
+#define NULL __null
 #else
-#define NULL ((void *)0)
+#define NULL 0
 #endif
+#endif
+#else /* __cplusplus */
+#undef NULL
+#define NULL ((void *)0)
+#endif /* __cplusplus */
 
 #ifdef __KERNEL__
 
-- 
1.7.7


-- 
 Lubos Lunak
 l.lunak@suse.cz

  reply	other threads:[~2012-04-14  6:43 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-13 19:24 Lubos Lunak
2012-04-13 19:39 ` Linus Torvalds
2012-04-13 21:02   ` Arnd Bergmann
2012-04-16  7:43     ` Martin Schwidefsky
2012-04-13 21:46   ` Lubos Lunak
2012-04-14  8:28     ` Arnd Bergmann
2012-04-13 22:01   ` Peter Seebach
2012-04-13 22:24     ` Linus Torvalds
2012-04-13 23:18       ` Lubos Lunak
2012-04-14  0:44         ` Linus Torvalds
2012-04-14  6:43           ` Lubos Lunak [this message]
2012-04-14  7:51             ` Linus Torvalds
2012-04-14  8:21               ` Lubos Lunak
2012-04-14  8:27                 ` Linus Torvalds
2012-04-14  8:54                   ` Lubos Lunak
2012-04-14  9:30                     ` Arnd Bergmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201204140843.08671.l.lunak@suse.cz \
    --to=l.lunak@suse.cz \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peter.seebach@windriver.com \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®