如何确定是否在Xcode中编译64位iOS [英] How to determine if compiling for 64-bit iOS in Xcode

查看:194
本文介绍了如何确定是否在Xcode中编译64位iOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑以下函数

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

CGSize 实际上包含两个 CGFloat s, CGFloat 的定义根据体系结构而变化:

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

因此,上述代码在64位系统上是错误的,需要更新类似

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
}

肯定有编译器宏/常量(对于Mac,我们可以使用 INTEL_X86 )但我无法在 64位转换指南

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.

如何确定正在构建的体系结构?

推荐答案

确定您是否正在编译64位,使用 __ LP64 __

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 __ 看台因为longs and pointers是64位并且是架构中立的。

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

根据你的转换指南它也适用于iOS:

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


编译64位
运行时时,编译器定义 __ LP64 __ 宏。

但是,处理用例的首选方法是使用 CGFLOAT_IS_DOUBLE 。无法保证 __ LP64 __ 总是意味着 CGFloat 是一个双倍,但它将保证 CGFLOAT_IS_DOUBLE

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

这篇关于如何确定是否在Xcode中编译64位iOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆