Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine if compiling for 64-bit iOS in Xcode

Consider the following function

CGSize CGSizeIntegral(CGSize size)
{
    return CGSizeMake(ceilf(size.width), ceilf(size.height));
}

CGSize actually consists of two CGFloats, and CGFloat's definition changes depending on the architecture:

typedef float CGFloat;// 32-bit
typedef double CGFloat;// 64-bit

So, the above code is wrong on 64-bit systems, and needs to be updated with something like

CGSize CGSizeIntegral(CGSize size)
{
#if 64_bit
    return CGSizeMake(ceil(size.width), ceil(size.height));
#else
    return CGSizeMake(ceilf(size.width), ceilf(size.height));
#endif
}

There is surely a compiler macro/constant for this (for Mac we can use INTEL_X86 for example) but I haven't been able to find this in the 64-bit transition guide.

How can I determine what architecture is being built for?

like image 218
SG1 Avatar asked Sep 17 '13 22:09

SG1


People also ask

How do you check iOS app is 32-bit or 64-bit?

Apple has included a new Settings pane in iOS 10.3 to easily check for installed 32-bit apps, and to see if there are updates available. To check, open Settings. Tap on General. Tap on About, and select Applications.

How do I make my 32-bit application 64-bit?

Same as above, click on Properties from the menu. Under Properties, click on the Compatibility tab. Click the box that says “Run this program in compatibility mode for:” and select the Windows version you want to use. Then, click Apply and try to run your application.


1 Answers

To determine if you are compiling for 64-bit, use __LP64__:

#if __LP64__
    return CGSizeMake(ceil(size.width), ceil(size.height));
#else
    return CGSizeMake(ceilf(size.width), ceilf(size.height));
#endif

__LP64__ stands for "longs and pointers are 64-bit" and is architecture-neutral.

According to your transition guide it applies for iOS as well:

The compiler defines the __LP64__ macro when compiling for the 64-bit runtime.

However, the preferred way to handle your use case is to use CGFLOAT_IS_DOUBLE. There is no guarantee that __LP64__ will always mean the CGFloat is a double, but it would be guaranteed with CGFLOAT_IS_DOUBLE.

#if CGFLOAT_IS_DOUBLE
    return CGSizeMake(ceil(size.width), ceil(size.height));
#else
    return CGSizeMake(ceilf(size.width), ceilf(size.height));
#endif
like image 116
Gerald Avatar answered Nov 09 '22 22:11

Gerald