How can I print a pointer in decimal notation?
None of the below produce the desired result when compiling with -Wall
. I understand the errors, and do want to compile with -Wall
. But then how can I print a pointer in decimal notation?
#include <stdio.h>
#include <stdlib.h>
int main() {
int* ptr = malloc(sizeof(int));
printf("%p\n", ptr); // Hexadecimal notation
printf("%u\n", ptr); // -Wformat: %u expects unsigned int, has int *
printf("%u\n", (unsigned int) ptr); // -Wpointer-to-int-cast
return EXIT_SUCCESS;
}
(This is needed because I'm using the pointers as node identifiers in a dot graph, and 0x..
is not a valid identifier.)