|
Message-Id: <20210815155157.692-1-ismael@iodev.co.uk> Date: Sun, 15 Aug 2021 17:51:57 +0200 From: Ismael Luceno <ismael@...ev.co.uk> To: musl@...ts.openwall.com Cc: Ismael Luceno <ismael@...ev.co.uk> Subject: [PATCH] Define NULL as nullptr when used in C++ 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@...ev.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
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.