mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] [PATCH] Define NULL as nullptr when used in C++
@ 2021-08-15 15:51 Ismael Luceno
  0 siblings, 0 replies; only message in thread
From: Ismael Luceno @ 2021-08-15 15:51 UTC (permalink / raw)
  To: musl; +Cc: Ismael Luceno

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-08-15 15:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-15 15:51 [musl] [PATCH] Define NULL as nullptr when used in C++ Ismael Luceno

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).