Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can nullptr be used as a variable argument (varargs)?

Tags:

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));
like image 279
Kerrek SB Avatar asked Sep 11 '13 13:09

Kerrek SB


1 Answers

§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) type std::nullptr_t is converted to type void* (4.10)...

like image 80
Igor Tandetnik Avatar answered Oct 02 '22 18:10

Igor Tandetnik