05-19-2006
134,
2
Join Date: Feb 2006
Last Activity: 3 February 2012, 11:19 PM EST
Location: Schenectady, NY
Posts: 134
Thanks Given: 0
Thanked 2 Times in 2 Posts
This will be far from a complete answer as there are many subtleties but I can at least cite my own experiences which may not be true for all compilers and architectures. That said, in a nutshell...
In most 32-bit environments, the data type int and all pointers were 4-bytes. On some systems, a long was also 4-bytes with a long long being 8-bytes. In most 64-bit environments, the int remains 4-bytes, the long is 8-bytes (as is the long long defined only for backward compatibility), and the pointer data type increased to 8-bytes.
Problems arise in code that ASSUME the size of each data type specifically that an int and a pointer are exactly the same length. As stated, in 32-bit environments, that is a safe bet however when moving to 64-bit compilers that is not necessarily true. As a result, programs that rely on a specific size of, say, a structure containing integers used as pointers are now in error as they have different memory allocations.
Compilers come with derived data types to be used when working with pointers and integers of varying size but most people -- myself included -- use the standard C datatypes. Those work fine, of course, but require extra caution especially if working with unions, bit-mapped data types, implicit datatype conversion, and such. Often inconsistencies can be overcome with explicit casting.
I hope my explanation has helped.
Last edited by hegemaro; 05-19-2006 at 12:52 PM..