The big difference between 32-bit and 64-bit architectures is that the address space is much larger on 64-bit architectures.
Therefore, the main difference in data types between these architectures is in types that store memory addresses, i.e., pointers.
For example, on a 32-bit architecture, sizeof(void*)
returns 4 bytes, while in a 64-bit architecture the same command returns 8 bytes. This difference is necessary for the entire address space to be effectively addressed.
There are other issues like setjmp
and longjmp
, but these are more closely associated with the instructions (ISA).
Anyway, you must change from int
for long
if you will use values that the int
do not behave, otherwise there is nothing to worry about in this direction.
The int
's of life are only problematic if you realize Casts between pointers and integers. Some libraries use this instead of using Opaque pointers. In these cases, the library is expected to take the necessary care to maintain consistency when the library is compiled in 64 bits, and the programmer must make use of the library’s data types, making these changes transparent.
Finally, care should be taken when fixing the size of structures containing pointers. For example:
typedef struct {
int *a;
} myStruct;
If we execute the command sizeof(myStruct)
in both architectures, we will get different sizes for the same structure.
Imagine the code:
myStruct p;
fread(&p, 4, 1, file);
I’m using an absurd example but it will serve to explain the point
On a 64-bit platform, it would not give the expected result, since the structure myStruct
has size 8 bytes, but as the structure size has been fixed in the command fread
, we will ignore 4 bytes of the file, which may cause absurd results or the crash of the application.
To avoid this is very simple: just use sizeof
:
myStruct p;
fread(&p, sizeof(p), 1, file);
Ok. Since I didn’t use these variables as pointer, I will keep the code as is. Thank you.
– IamInTrouble