Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if app is built in 32 or 64-bit?

Tags:

ios

iphone

How can I check whether my app is compiled in 32-bit or 64-bit ?

This is helpful to debug low level code (working with buffers for example).

like image 706
Harry Avatar asked Sep 27 '13 06:09

Harry


2 Answers

A compile time check would involve #ifdef'ing for __LP64__, which is ARM's data type size standard. A runtime solution would involve checking the size of pointers, like so:

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

Thankfully, pointer sizes are the one thing that the different standards for compiling 64-bit code seem to agree on.

like image 107
CodaFi Avatar answered Nov 18 '22 08:11

CodaFi


#ifdef __LP64__
    NSLog(@"64-bit\t");
#else
    NSLog(@"32-bit\t");
#endif
like image 16
GW.Rodriguez Avatar answered Nov 18 '22 08:11

GW.Rodriguez