Quote:
|
Originally Posted by lectricpharaoh
On most common systems, sizeof(int) == sizeof(int *), but this isn't always true.
|
On
some common systems it is true, but on some
other common systems it is not.
Quote:
|
Originally Posted by lectricpharaoh
As a case when it is not true, take old software running on an 80x86 platform that uses the segmented memory model. In this case, for a full pointer (aka 'far pointer'), it was 32 bits (two words, one each for segment and offset), whereas an int was often only 16 bits (one word).
|
The default pointer size used on older 8086 machines was 16 bit. Later on (80286 and later) the hardware was able to support 32 bit operations, and eventually some compilers evolved to take advantage of that. Initially, by default, those compilers supported 16 bit pointers (and referred to as "near" pointers). A far pointer, as you say was a (segment, offset) pair and, technically, not all far pointers were 32 bit pointers -- not all of the 32 bits were actually used.
All that aside, there is really little point in debating whether an int and a pointer are the same size, or which is the "common" usage. They are the same size on some target machines, and are different sizes on some other machines --- and both types of machines are quite common. So writing code that assumes they are the same size is asking for trouble: either you get "lucky" and run into trouble because your machine has int and pointers of different sizes. Or your get unlucky, and get a program that appears to run well, until you decide to port it to another machine or (even) to another compiler on the same machine.