3 ms·
Actually %p can only be used to print values of type void * . Since there is no requirement that other pointer types be converted to void * when calling a varar
by unwind 12y ago
Actually %p can only be used to print values of type void * . Since there is no requirement that other pointer types be converted to void * when calling a varargs function, you need to cast:
int x = 4711;
printf("x is at %p\n", (void *) &x);
Of course the conversion will be a null operation on many modern systems, where all data pointer types are implemented identically, but this is what the language standard requires.
- simias 12y agoInteresting, I thought pointer representation could only be different for function pointers. Has there ever been an architecture where data pointers could have a different representations?
- exDM69 12y ago> Interesting, I thought pointer representation could only be different for function pointers. Yes, this is the case, e.g. in micro controllers, where the program is stored in EEPROM. You can store data in program memory (e.g. constant strings) but you need to access it in a special manner. > Has there ever been an architecture where data pointers could have a different representations? At least conceptually, this was the case in early GPUs, where there were different memories for different access patterns. Memory area for constants, another one for global read only memory, and a third area for thread-specific read-write -memory and a fourth that was shared between groups of threads. Whether they were actually different physical memories and whether they had different address spaces is another issue (they at least partially did, some stuff was on chip, some was external DRAM), but this was how it was conceptually seen by the programmer and the way early GPGPU APIs worked (early versions of CUDA and OpenCL).
- nuxi 12y agoYes, different representations as well as non-zero null pointers. More from comp.lang.c FAQ at http://c-faq.com/null/machexamp.html http://c-faq.com/null/machexamp.html.
- simias 12y agoAh, very interesting, thanks!