Skip to content

Commit f093899

Browse files
[C++ for OpenCL] Allow NULL to be implementation defined macro. (#502)
* [C++ for OpenCL] Allow NULL to be implementation defined macro. This is to align C++ for OpenCL with C++17.
1 parent 698ae31 commit f093899

1 file changed

Lines changed: 16 additions & 15 deletions

File tree

cxx4opencl/diff2openclc.txt

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -67,35 +67,37 @@ void foo(){
6767
----------
6868

6969
[[null_literal]]
70-
===== Null literal
70+
===== Null pointer constant
7171

72-
In C and OpenCL C the null literal is defined using other
72+
In C and OpenCL C the null pointer constant is defined using other
7373
language features as it is not represented explicitly i.e.
7474
commonly it is defined as
7575

7676
[source,c]
7777
----------
78-
#define NULL (void*)0
78+
#define NULL ((void*)0)
7979
----------
8080

81-
In {cpp} there is an explicit builtin literal `nullptr`
82-
that should be used instead ({cpp}17 `[lex.nullptr]`).
81+
In {cpp}17 there is an explicit builtin pointer literal `nullptr` that should
82+
be used instead ({cpp}17 `[lex.nullptr]`).
8383

84-
{cpp} for OpenCL does not define `NULL` and therefore any
85-
source code using it must be modified to use `nullptr`
86-
instead. However as a workaround to avoid large modifications
87-
`NULL` can also be defined/aliased to `nullptr` in custom
88-
headers or using command line flag `-D`. It is not recommended
89-
to reuse the C definition of `NULL` in {cpp} for OpenCL as it may
90-
cause compilation failures in cases that work for C.
84+
`NULL` macro definition in {cpp} for OpenCL follows {cpp}17
85+
`[support.types.nullptr]` where it is an implementation defined macro and it
86+
is not guaranteed to be the same as in OpenCL C. Reusing the definition of
87+
`NULL` from OpenCL C does not guarantee that any code with NULL is legal in
88+
{cpp} for OpenCL even if it is legal in OpenCL C.
9189

9290
[source,c]
9391
----------
92+
#define NULL ((void*)0)
9493
void foo(){
9594
int *ptr = NULL; // invalid initialization of int* with void*
9695
}
9796
----------
9897

98+
To improve code portability and compatibility, implementations are
99+
encouraged to define `NULL` as an alias to pointer literal `nullptr`.
100+
99101
===== Use of restrict
100102

101103
{cpp}17 does not support `restrict` and therefore {cpp} for OpenCL
@@ -140,9 +142,8 @@ Variadic macros can be used normally as per {cpp}17 `[cpp.replace]`.
140142

141143
===== Predefined macros
142144

143-
The predefined macros `+__OPENCL_C_VERSION__+` and `NULL` (see also
144-
<<null_literal, _Null literal_>>), described in `OpenCL C v2.0 s6.10`,
145-
are not supported.
145+
The macro `+__OPENCL_C_VERSION__+` described in `OpenCL C v2.0 s6.10`,
146+
is not defined.
146147

147148
The following new predefined macros are added in {cpp} for OpenCL:
148149

0 commit comments

Comments
 (0)