Is appending '0' as flag to printf
%p format specifier correct or not?
#include <stdio.h>
int main()
{
int a = 42;
void* p = &a;
printf("Pointer address: %08p", p);
return 0;
}
Also on Ideone.
Compiling some code similar to the above, I got no warning or whatsoever from Microsoft Visual C++ 2015, but a warning from GCC 5.4.0:
"warning: '0' flag used with '%p' gnu_printf format [-Wformat]"
Reading from cppreference printf, I see that:
0 : for integer and floating point number conversions, leading zeros are used to pad the field instead of space characters. For integer numbers it is ignored if the precision is explicitly specified. For other conversions using this flag results in undefined behavior. It is ignored if - flag is present.
As far as I can interpret, %p is for pointer address, which is an integer number after all, so does this undefined behavior apply to %p?
If not, why the GCC -Wformat warning?