xref: /illumos-gate/usr/src/uts/common/sys/null.h (revision d8109ce4330e1b8ad6c29f9fccacec969066bb9d)
1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2014-2016 PALO, Richard.
14  */
15 
16 #ifndef _SYS_NULL_H
17 #define	_SYS_NULL_H
18 
19 #include <sys/feature_tests.h>
20 
21 #ifndef	NULL
22 
23 #if defined(__sparc)
24 /*
25  * SPARC code is not yet NULL pointer clean.
26  */
27 
28 /*
29  * POSIX.1-2008 requires that the NULL macro be cast to type void *.
30  * Historically, this has not been done, so we only enable this in a
31  * POSIX.1-2008 compilation environment.
32  */
33 
34 #if defined(_XPG7) && !defined(__cplusplus)
35 #define	NULL	((void *)0)
36 #else
37 
38 /*
39  * ISO C++ requires that the NULL macro be a constant integral type evaluating
40  * to zero until C++11, and an integer or pointer literal with value zero from
41  * C++11 onwards.
42  */
43 
44 #if defined(__cplusplus) && __cplusplus >= 201103L
45 #define	NULL	nullptr
46 #else
47 #if defined(_LP64)
48 #define	NULL	0L
49 #else
50 #define	NULL	0
51 #endif	/* _LP64 */
52 #endif	/* C++11 */
53 #endif	/* _XPG7 */
54 #else
55 /*
56  * POSIX.1-2008 requires that the NULL macro be cast to type void *.
57  */
58 
59 #if !defined(__cplusplus)
60 #define	NULL	((void *)0)
61 #else
62 
63 /*
64  * ISO C++ requires that the NULL macro be a constant integral type evaluating
65  * to zero until C++11, and an integer or pointer literal with value zero from
66  * C++11 onwards.
67  */
68 
69 #if __cplusplus >= 201103L
70 #define	NULL	nullptr
71 #else
72 #if defined(_LP64)
73 #define	NULL	0L
74 #else
75 #define	NULL	0
76 #endif	/* _LP64 */
77 #endif	/* C++11 */
78 #endif	/* !__cplusplus */
79 #endif	/* __sparc */
80 
81 #endif	/* NULL */
82 
83 #endif	/* _SYS_NULL_H */
84