Click to See Complete Forum and Search --> : size of pointer
sunnypalsingh
October 19th, 2005, 07:11 AM
In turbo C sizeof(pointer)....shows 2 bytes.....whereas in VC6.0 it shows 4 bytes...so does it means it is compiler dependent.......i guess it is......somewhere i read.....i don't remember that...size of pointer is atleast equal to unsigned int or unsigned long int(don't remember which of them)....plz help
Graham
October 19th, 2005, 07:28 AM
It's architecture dependent. AFAIR, there's nothing in the standard that specifies the size of a pointer with respect to the size of any other type.
rdrast
October 19th, 2005, 07:34 AM
Turbo C targets 16 bit enviornments, so uses 16 bit (two byte) pointers (welcome back days of Segment:offset). VC6 targets primarily 32 bit enviornments, and uses 32 bit (four byte) pointers.
cilu
October 19th, 2005, 07:48 AM
A Beginner's Guide to Pointers (http://www.codeproject.com/cpp/pointers.asp)
The size of a pointer is 2 bytes on 16 bits platform, and 4 bytes on 32 bit platforms.
sunnypalsingh
October 19th, 2005, 09:59 AM
Well i tested on turbo C compiler it showed 2 bytes....in VC 6.0 it showed 4 bytes.....on the same system(32-bit).....is that because in turbo c pointers are by default near pointers....
Paul McKenzie
October 19th, 2005, 10:17 AM
Well i tested on turbo C compiler it showed 2 bytes....in VC 6.0 it showed 4 bytes.....on the same system(32-bit).....is that because in turbo c pointers are by default near pointers....It doesn't matter what system you run Turbo C on -- it won't magically change pointer size because you're running the ancient (more than 15 years old) Turbo C program on a modern 32-bit Windows OS.
Those "near" and "far" pointers were used in 16-bit MSDOS environments, and the Turbo C compiler is made to compile 16-bit MSDOS programs. If you changed something called the "memory model" when compiling to the "Large Model", you will see by default the pointers contain both segment and offset, making them 32-bits wide. Regardless, the program that is produced will (and always will be) a 16-bit MSDOS program when using Turbo C.
Regards,
Paul McKenzie
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.