Skip to content

Commit d66bd1f

Browse files
committed
<stddef.h>: define NULL with type void *
ISO C2011 7.19 para 3 says "NULL, which expands to an implementation-defined null pointer constant" ISO C2011 6.3.2.3 para 3 says "An integer constant expression with the value 0, or such an expression cast to type void *, is called a null pointer constant." So, it seems NULL can be defined either as "0" or as "(void *) 0". However, the two definitions are not equivalent in the context of a call to a variadic or unprototyped function: passing 0 when the function expects a pointer value can go wrong if sizeof(int) != sizeof(void *). This commit changes the definition of NULL to the safer one: This is what GCC and Clang do in C mode; they use "#define NULL 0" for C++ only. Fixes issue AbsInt#265
1 parent 5382c3c commit d66bd1f

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

runtime/include/stddef.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ typedef signed int wchar_t;
108108

109109
#if defined(_STDDEF_H) || defined(__need_NULL)
110110
#ifndef NULL
111-
#define NULL 0
111+
#define NULL ((void *) 0)
112112
#endif
113113
#undef __need_NULL
114114
#endif

0 commit comments

Comments
 (0)