Will the C89 standard allow me to cast void * to ptrdiff_t so I can print the memory location as hexadecimal?
For example:
static const char *dig = "0123456789abcdef";
char buf[16], *ptr = buf; /* Need 16 bytes when sizeof(void *) == 8 */
void *val;
ptrdiff_t tmp = (const unsigned char *) val - (const unsigned char *) 0;
do {
*buf++ = dig[tmp & 0xf];
tmp >>= 4;
} while (tmp);
do {
putc(*--ptr);
} while (ptr > buf);
Context: I am writing a printf() function in kernel space.