Subriemanian said:
I have been thinking that all pointers(to any obejct) have the same
size. The size of a pointer is the size of an Int. This is beause a
memory location is addressed by an Int. Is that right/wrong?
both of these are architecture dependent.
however, as it so happens, both are true for 32 bit x86 (except in certain
edge cases, such as an x86-based AS/400, ...).
only the former is true for x86-64 (where int remains 32 bits, but pointers
are 64 bits).
and neither is necessarily true on non-x86 architectures (though the former
is true, most of the time, as 'most' archs are also byte-addressed, and use
an 8-bit byte as the basic unit of memory). but, then again, on
word-addressed archs, it is up to the compiler how to handle the different
pointer types (afaik, it was fairly common practice to have all pointers be
the same size, but to ignore the low-order bits for non-byte-addressed
objects, or to have the pointers be pad-extended on the left-hand-side even
though many of the high-order bits were unused).
in part, a lot of this is catering to the general naivity of many coders
when it comes to oddball archs, and so seeming more 'normal' is often
preferable even in the face of reduced performance...
but, for portability, rely on neither. or, if targetting a specific arch, no
the specifics of that arch well...
for example, I know what is generally done on x86 and x86-64 down to the
machine code level, but can say much less about, say, PPC, Motorola, or ARM
based systems.
other people who target ARM, for example, likely also know about what the
compilers tend to output.
or such...