Possible Duplicates:
Are there are any platforms where pointers to different types have different sizes?
Can the Size of Pointers Vary Depending on what's Pointed To?
Take 32-bit machine for example. It almost is 32-bit long regardless of what type, inclusive of original type or aggregate type. I think the reason is pointer is actually a index in the vitual address space, so it has the same length as machine does.
Howerver, the standard does't require this:
6.2.5.27:
A pointer to void shall have the same representation and alignment requirements as a pointer to a character type.39) 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.
What is more interesting is that it does't mention the function pointers.
So I want to konw why? Except the truth that in early MS C ,there has so-called far pointer and near pointer, due to the bizarre segment design in early Intel CPU. But nowadays, this is different, the paging and vitual memory will avoid such things.
Another question:
void *
should be casted to any type. So if there is different pointer length. For example, int *
4-byte long and function pointer 8-byte long (Just a example). So how the cast implement? void *
has a fixed bit-mode, will it scale itself to cast into 4-byte int*
and 8-byte function pointer?