Reputation: 477040
Can I use the nullptr
keyword as an argument for a variable function? If so, does it undergo any kind of standard conversion, and what is the type of the resulting value?
Concretely, is the following correct?
std::printf("%p", nullptr);
Or does it have to be:
std::printf("%p", static_cast<void *>(nullptr));
Upvotes: 20
Views: 889
Reputation: 52471
§5.2.2p7 When there is no parameter for a given argument, the argument is passed in such a way that the receiving function can obtain the value of the argument by invoking
va_arg
(18.10)... An argument that has (possibly cv-qualified) typestd::nullptr_t
is converted to typevoid*
(4.10)...
Upvotes: 22
Reputation: 153919
The standard says that any argument of type nullptr_t
will be converted to void*
when matching ...
. So the call is correct without the cast.
EDIT:
From the standard (§5.2.2/7):
When there is no parameter for a given argument, the argument is passed in such a way that the receiving function can obtain the value of the argument by invoking
va_arg
. The lvalue-to-rvalue, array-to-pointer, and function-to-pointer standard conversions are performed on the argument expression. An argument that has (possibly cv-qualified) typestd::nullptr_t
is converted to typevoid*
.
Upvotes: 11