How the data is formatted via %p
is implementation-defined. For example, you may get ugly result when you create hex-dumping software with %p
:
For example, running this,
#include <stdio.h>
int main(void) {
char data[64];
/* read data from file in real application */
for (int i = 0; i < 64; i++) data[i] = (char)i;
puts("--- %x version ---");
for (int i = 0; i < 64; i++) {
printf(" %02X", (unsigned char)data[i]);
if ((i + 1) % 16 == 0) putchar('\n');
}
puts("--- %p version ---");
for (int i = 0; i < 64; i++) {
printf(" %p", (void*)(unsigned char)data[i]);
if ((i + 1) % 16 == 0) putchar('\n');
}
return 0;
}
You may get this:
--- %x version ---
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F
20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F
30 31 32 33 34 35 36 37 38 39 3A 3B 3C 3D 3E 3F
--- %p version ---
(nil) 0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 0xa 0xb 0xc 0xd 0xe 0xf
0x10 0x11 0x12 0x13 0x14 0x15 0x16 0x17 0x18 0x19 0x1a 0x1b 0x1c 0x1d 0x1e 0x1f
0x20 0x21 0x22 0x23 0x24 0x25 0x26 0x27 0x28 0x29 0x2a 0x2b 0x2c 0x2d 0x2e 0x2f
0x30 0x31 0x32 0x33 0x34 0x35 0x36 0x37 0x38 0x39 0x3a 0x3b 0x3c 0x3d 0x3e 0x3f
In this experiment, 0x
prefixes that I don't want are added in %p
version and also 0
is printed as (nil)
with %p
.