Check if the application was created in 32 or 64-bit mode?

How to check if my application compiled in 32-bit or 64-bit version?

This is useful for debugging low-level code (for example, for working with buffers).

+7
ios iphone
source share
3 answers

Compile-time checking will include #ifdef 'ing for __LP64__ , which is the standard for ARM data size. The runtime should include checking the size of the pointers, for example:

 if (sizeof(void*) == 4) { // Executing in a 32-bit environment } else if (sizeof(void*) == 8) { // Executing in a 64-bit environment } 

Fortunately, pointer sizes are the only things that different standards agree on for compiling 64-bit code.

+18
source share
 #ifdef __LP64__ NSLog(@"64-bit\t"); #else NSLog(@"32-bit\t"); #endif 
+16
source share

You can check the size of the pointer. I think that on 32-bit it is 4 bytes, and on 64 it should be 8.

 if( sizeof(void*) == 4 ) then 32bit else 64bit 
+2
source share

All Articles