News for hackers. Stuff that matters.
Re:C Pointers Explained, Really (2012) by unwind on Tuesday November 25, 2014 @03:52AM (#8656922)
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.
Re:C Pointers Explained, Really (2012) by simias on Tuesday November 25, 2014 @03:55AM (#8656926)
Interesting, 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?
Re:C Pointers Explained, Really (2012) by exDM69 on Tuesday November 25, 2014 @04:09AM (#8656957)
> 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).

Re:C Pointers Explained, Really (2012) by nuxi on Tuesday November 25, 2014 @04:25AM (#8656991)
Yes, different representations as well as non-zero null pointers. More from comp.lang.c FAQ at http://c-faq.com/null/machexamp.html.
Re:C Pointers Explained, Really (2012) by simias on Tuesday November 25, 2014 @05:04AM (#8657077)
Ah, very interesting, thanks!