As I was writing a unit test, I stumbled upon some odd behavior from glibc
, regarding "%p"
and the NULL
pointer.
If I have a line such as printf("NULL pointer is %p\n", NULL);
, then I see NULL pointer is (nil)
printed to the screen, as I expected.
If I instead use the wide-character version: wprintf(L"NULL pointer is %p\n", NULL);
, then it prints out NULL pointer is (
, and stops at the opening parenthesis. If I print a non-NULL
pointer, it prints that pointer, both normal and wide-character versions. Is this a known bug of glibc
, or am I just missing something?
NB: I realize that the C standard says that pointers with %p
are converted in an implementation-defined manner; it just seems unusual to just print (
for a NULL
pointer.
'
) around the%p
, but they do not appear in the result strings. Is this a typo in the question? – StomatitisNULL
, have you triedL'\0'
? – Trifling%p
expects a pointer, whereasL'\0'
is an integer constant. Regardless, it still gives the same result. – Findprintf
andwprintf
on the same stream - once a stream is oriented as either wide character or not, it can't be changed – Find