mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Ismael Luceno <ismael@iodev.co.uk>
To: musl@lists.openwall.com
Cc: Ismael Luceno <ismael@iodev.co.uk>
Subject: [musl] [PATCH] Define NULL as nullptr when used in C++
Date: Sun, 15 Aug 2021 17:51:57 +0200	[thread overview]
Message-ID: <20210815155157.692-1-ismael@iodev.co.uk> (raw)

This should be safer for casting and more compatible with existing code
bases that wrongly assume it must be defined as a pointer.

Signed-off-by: Ismael Luceno <ismael@iodev.co.uk>
---
 include/locale.h | 4 +++-
 include/stddef.h | 4 +++-
 include/stdio.h  | 4 +++-
 include/stdlib.h | 4 +++-
 include/string.h | 4 +++-
 include/time.h   | 4 +++-
 include/unistd.h | 4 +++-
 include/wchar.h  | 4 +++-
 8 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/include/locale.h b/include/locale.h
index ce384381c6bd..11106fea878a 100644
--- a/include/locale.h
+++ b/include/locale.h
@@ -7,7 +7,9 @@ extern "C" {
 
 #include <features.h>
 
-#ifdef __cplusplus
+#if __cplusplus >= 201103L
+#define NULL nullptr
+#elif defined(__cplusplus)
 #define NULL 0L
 #else
 #define NULL ((void*)0)
diff --git a/include/stddef.h b/include/stddef.h
index bd753853503d..f25b86396e80 100644
--- a/include/stddef.h
+++ b/include/stddef.h
@@ -1,7 +1,9 @@
 #ifndef _STDDEF_H
 #define _STDDEF_H
 
-#ifdef __cplusplus
+#if __cplusplus >= 201103L
+#define NULL nullptr
+#elif defined(__cplusplus)
 #define NULL 0L
 #else
 #define NULL ((void*)0)
diff --git a/include/stdio.h b/include/stdio.h
index 3604198c3e50..d1ed01f03f8f 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -25,7 +25,9 @@ extern "C" {
 
 #include <bits/alltypes.h>
 
-#ifdef __cplusplus
+#if __cplusplus >= 201103L
+#define NULL nullptr
+#elif defined(__cplusplus)
 #define NULL 0L
 #else
 #define NULL ((void*)0)
diff --git a/include/stdlib.h b/include/stdlib.h
index b54a051fe9fd..66fff9a04ca4 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -7,7 +7,9 @@ extern "C" {
 
 #include <features.h>
 
-#ifdef __cplusplus
+#if __cplusplus >= 201103L
+#define NULL nullptr
+#elif defined(__cplusplus)
 #define NULL 0L
 #else
 #define NULL ((void*)0)
diff --git a/include/string.h b/include/string.h
index 795a2abcd990..43ad0942edd5 100644
--- a/include/string.h
+++ b/include/string.h
@@ -7,7 +7,9 @@ extern "C" {
 
 #include <features.h>
 
-#ifdef __cplusplus
+#if __cplusplus >= 201103L
+#define NULL nullptr
+#elif defined(__cplusplus)
 #define NULL 0L
 #else
 #define NULL ((void*)0)
diff --git a/include/time.h b/include/time.h
index 5494df183673..3d94837205ad 100644
--- a/include/time.h
+++ b/include/time.h
@@ -7,7 +7,9 @@ extern "C" {
 
 #include <features.h>
 
-#ifdef __cplusplus
+#if __cplusplus >= 201103L
+#define NULL nullptr
+#elif defined(__cplusplus)
 #define NULL 0L
 #else
 #define NULL ((void*)0)
diff --git a/include/unistd.h b/include/unistd.h
index 130640260368..ee2dbe8aff0c 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -15,7 +15,9 @@ extern "C" {
 #define SEEK_CUR 1
 #define SEEK_END 2
 
-#ifdef __cplusplus
+#if __cplusplus >= 201103L
+#define NULL nullptr
+#elif defined(__cplusplus)
 #define NULL 0L
 #else
 #define NULL ((void*)0)
diff --git a/include/wchar.h b/include/wchar.h
index 88eb55b18cc1..ed5d774dfa96 100644
--- a/include/wchar.h
+++ b/include/wchar.h
@@ -38,7 +38,9 @@ extern "C" {
 #define WCHAR_MIN (-1-0x7fffffff+L'\0')
 #endif
 
-#ifdef __cplusplus
+#if __cplusplus >= 201103L
+#define NULL nullptr
+#elif defined(__cplusplus)
 #define NULL 0L
 #else
 #define NULL ((void*)0)
-- 
2.32.0


                 reply	other threads:[~2021-08-15 15:52 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20210815155157.692-1-ismael@iodev.co.uk \
    --to=ismael@iodev.co.uk \
    --cc=musl@lists.openwall.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).