NULL to intptr_t or uintptr_tAuthors: Jay Ghiron
Date: 2026-05-06
Submitted against: C23
Status: Open
Before C23, the following program was always valid if intptr_t was
defined:
#include<stddef.h>
#include<stdint.h>
int main(){
(intptr_t)NULL;
}
However, NULL is now allowed to be defined as nullptr which cannot
be cast to an integer type. It seems unnecessary to forbid this, and
C++ allows using nullptr in place of (void*)0 in pointer to
integer conversions.
Modify C23 6.5.5 paragraph 4:
The type
nullptr_tshall not be converted to any floating typeother than.void,boolor a pointer type
Note: The text seems to currently forbid (nullptr_t)nullptr despite
the next sentence intending to allow it.
Replace C23 6.3.3.4:
A value of type
nullptr_tcan be converted to an integer type, the result is equivalent to converting(void*)0to the same integer type. A value of typenullptr_tcan be converted to a pointer type ornullptr_t, the result is a null pointer.
Note: The text currently says "The type
nullptr_tcan be converted ..." which is inconsistent with how other conversions are described on values rather than types.
Note: It seems unnecessary to define the conversion of nullptr_t to
void here.
Comment from Jay Ghiron on 2026-10-09:
It appears that the suggested correction removes any wording that
defines conversion of a null pointer constant other than nullptr to
nullptr_t. Additionally, it appears that the previous section which
defines conversions with pointers already defines conversion of
nullptr_t to pointer types. Alternative wording for C23 6.3.3.4:
A value of type
nullptr_tcan be converted to an integer type, the result is equivalent to converting(void*)0to the same integer type. A null pointer constant or a value of typenullptr_tcan be converted tonullptr_t, the result in either case isnullptr.
Comment from Issues list maintainer on 2026-11-27:
This issue was discussed at the November 2026 (Búzios) meeting of WG14. Jens Gustedt suggested that if such a change is made, there should also be a requirement that converting a null pointer constant of pointer type to an integer type produces integer zero, and took an action item to write wording for this, possibly in a paper.
Comment from Jay Ghiron on 2026-11-30:
If a null pointer constant of pointer type would always convert to
zero then (void*)(uintptr_t)(void*)0 may not be valid if a
non-constant zero converted to void* does not map to a null pointer.
The suggested correction would keep the validity of the original
program, the resulting integer may not be useful though that was the
case before C23. Defining the conversion of nullptr_t to integer
types is a simple fix that aligns the behavior with C++, whence
nullptr_t came.