You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Port 32-bit code to 64-bit
If your code already runs on the desktop or iOS, you shouldn't need to do any extra work for Android. If this is the first time your code has been built for a 64-bit system, the main issue you must address is that pointers no longer fit in 32-bit integer types like int.
Update code that stores pointers in types such as int, unsigned, or uint32_t. On Unix systems, long matches the pointer size, but this isn't true on Windows. Instead, use the intention-revealing types uintptr_t or intptr_t. To store the difference between two pointers, use the ptrdiff_t type.
You should always prefer the specific, fixed-width integer types defined in <stdint.h> rather than non fixed-width types such as int or long, even for non-pointers.
Use the following compiler flags to catch cases where your code is incorrectly converting between pointers and integers:
-Werror=pointer-to-int-cast
-Werror=int-to-pointer-cast
-Werror=shorten-64-to-32
Java classes with int fields that hold pointers to C/C++ objects have the same problem. Search for jint in your JNI source and ensure that you switch to long on the Java side and jlong on the C++ side.
Implicit function declarations are a lot more dangerous for 64-bit code. C/C++ assume that the return type of an implicitly declared function (that is, a function that the compiler hasn't seen a declaration for) is int. If the actual return type of your function is a pointer, this works fine on a 32-bit system where your pointer fits into an int. However, on a 64-bit system, the compiler drops the top half of your pointer. For example:
// This function returns a pointer:
// extern char* foo();
// If you don't include a header that declares it,
// when the compiler sees this:
char* result = foo();
// Instead of compiling that to:
result = foo();
// It compiles to something equivalent to:
result = foo() & 0xffffffff;
// Which will then cause a SIGSEGV if you try to dereference result
Port 32-bit code to 64-bit
If your code already runs on the desktop or iOS, you shouldn't need to do any extra work for Android. If this is the first time your code has been built for a 64-bit system, the main issue you must address is that pointers no longer fit in 32-bit integer types like int.
Update code that stores pointers in types such as int, unsigned, or uint32_t. On Unix systems, long matches the pointer size, but this isn't true on Windows. Instead, use the intention-revealing types uintptr_t or intptr_t. To store the difference between two pointers, use the ptrdiff_t type.
You should always prefer the specific, fixed-width integer types defined in <stdint.h> rather than non fixed-width types such as int or long, even for non-pointers.
Use the following compiler flags to catch cases where your code is incorrectly converting between pointers and integers:
-Werror=pointer-to-int-cast
-Werror=int-to-pointer-cast
-Werror=shorten-64-to-32
Java classes with int fields that hold pointers to C/C++ objects have the same problem. Search for jint in your JNI source and ensure that you switch to long on the Java side and jlong on the C++ side.
Implicit function declarations are a lot more dangerous for 64-bit code. C/C++ assume that the return type of an implicitly declared function (that is, a function that the compiler hasn't seen a declaration for) is int. If the actual return type of your function is a pointer, this works fine on a 32-bit system where your pointer fits into an int. However, on a 64-bit system, the compiler drops the top half of your pointer. For example:
// This function returns a pointer:
// extern char* foo();
// If you don't include a header that declares it,
// when the compiler sees this:
char* result = foo();
// Instead of compiling that to:
result = foo();
// It compiles to something equivalent to:
result = foo() & 0xffffffff;
// Which will then cause a SIGSEGV if you try to dereference result
Reference
https://developer.android.com/google/play/requirements/64-bit
The text was updated successfully, but these errors were encountered: