Cheng said:
I tried in g++
sizeof(int*)
siezof(long*)
sizeof(Foo*)//Foo is a self-defined class
They all has same size. Do all pointers have same size in a given
platform with given compiler?
Thanks & Regards
Not necessarily. In the (good/bad) old days of programming 16 bit DOS
systems... There was the notion of a "near" and a "far" pointer - near
pointers being 16 bit offsets in the current segment, far pointers being
segment
ffset pairs (32 bits, but resolved to 24 thanks to overlap...)
You could have various memory "models" where all pointers were near, or
data near and code far, or code near and data far, both far...
I would imagine that in some embedded systems with their constrained
memory configurations you could find oddball configurations too.
So I wouldn't assume that all pointers are created equal and/or take the
same space. That leads to dangerous thinking like casting them to int
or long or void*... ;-)