C++ Logo

std-discussion

Advanced search

Re: Is (0) a null pointer constant?

From: language.lawyer_at <language.lawyer_at_[hidden]>
Date: Fri, 21 Jul 2023 14:48:41 +0500
> Is a parenthesised integer literal with value zero a null pointer
> constant?
>
> The current wording doesn't seem to allow that. [conv.ptr] says that "a
> null pointer constant is an integer literal ([lex.icon]) with value
> zero ...", which should exclude (0).
>
> All of gcc, clang and MSVC accept `void * ptr = (0);`.

https://timsong-cpp.github.io/cppwp/n4868/expr.prim.paren#1.sentence-2: The parenthesized expression can be used in exactly the same contexts as those where E can be used, and with the same meaning, except as otherwise indicated.

Received on 2023-07-21 09:48:47