When converting 32-bit to 64-bit code in iOS

1

I know there is a lot of information about converting 32-bit to 64-bit code on iOS. However, I still have many doubts and I believe they are the same as other people, especially in the question of int variables. For example, as I could see, int is used for 32-bit and long for 64-bit. However, I'm developing an app that has only variables of type int , I put the architecture to Standard architectures (including 64-bit) and I execute it in the simulator. The app runs correctly without any warning or error. Even running (seemingly) correctly, do I have to change the variables to type long ?

    
asked by anonymous 29.10.2014 / 15:54

2 answers

2

No. Maybe it might need to change if any int is used as a pointer. Essentially what really changes when it goes 64-bit is the pointer size you generally do not have to worry about. Worry is needed only when you try to exchange numeric types with pointers.

    
29.10.2014 / 16:18
2

The big difference between 32-bit and 64-bit architectures is the address space that is much larger in 64-bit architectures.

So the main difference in data types between these architectures is in types that store memory addresses, that is, pointers.

For example, in a 32-bit architecture, sizeof(void*) returns 4 bytes, whereas in a 64-bit architecture the same command returns 8 bytes. This difference is required for all address space to be effectively addressed.

There are other issues like setjmp and longjmp , but these are more associated with the (ISA) instructions.

Finally, you should change from int to long if you are going to use values that int do not hold, otherwise there is no need to worry about this.

% of life% s are only problematic if you perform 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 data types, making these changes transparent.

Finally, care must be taken when setting the size of structures containing pointers. For example:

typedef struct {
    int *a;
} myStruct;

If we run the int command on the two 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 that will serve to explain the point

On a 64-bit platform, it would not give the expected result, since the sizeof(myStruct) structure has size 8 bytes, but since the size of the structure was fixed in the myStruct command, 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 fread :

myStruct p;
fread(&p, sizeof(p), 1, file);
    
29.10.2014 / 16:26