Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What systems out there use non-uniform pointer representation? [duplicate]

Possible Duplicate:
Are there are any platforms where pointers to different types have different sizes?

I have read in several places that pointers of different types may have different representations in standard-conforming C implementations. This is one thing that makes it necessary to cast pointer arguments to printf, e.g.

int foo;
printf("address is %p\n", (void *) &foo);

I was skeptical of this and poked through the C99 standard (document WG14 N1256, available at http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf). At 6.2.5.27 it reads:

A pointer to void shall have the same representation and alignment requirements as a pointer to a character type. Similarly, pointers to qualified or unqualified versions of compatible types shall have the same representation and alignment requirements. All pointers to structure types shall have the same representation and alignment requirements as each other. All pointers to union types shall have the same representation and alignment requirements as each other. Pointers to other types need not have the same representation or alignment requirements.

So, it does indeed sound like a conforming C99 implementation could use different representations for pointers of different types.

My question is this: what C implementations/architectures exist that actually use different representations for pointers of different types?

like image 548
Brad Larsen Avatar asked Feb 27 '23 03:02

Brad Larsen


2 Answers

Classic Cray (don't know about their new products) couldn't address characters with regular pointers, so char* and therefore void* were different from native vector pointers.

(See Keith's comment below, though. There may have been different ABI's in use, and by rotating the the low-order address bits to the high-order end, they did sometimes make the "fine" and "coarse" pointers compatible to a degree.)

like image 136
Potatoswatter Avatar answered Mar 02 '23 20:03

Potatoswatter


Probably the most well-known is the real mode x86 processors, which could have 16-bit data pointers and 32-bit function pointers depending on the memory model you chose (or you could have 32-bit data pointers with 16-bit function pointers, or something yet again different...).

like image 27
Michael Burr Avatar answered Mar 02 '23 20:03

Michael Burr