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

前端 未结 2 555
抹茶落季
抹茶落季 2021-02-13 00:28

Consider the following function

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

CGSi

2条回答
  •  广开言路
    2021-02-13 01:01

    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
    

提交回复
热议问题