[英]%d formatting for both 32-bit and 64-bit
NSInteger precedence = [self operatorPrecedence];
[d appendFormat:@"precedence:%d, ", precedence];
gives: 得到:
Warning: Format specifies type 'int' but the argument has type 'NSInteger' (aka 'long')
警告:Format指定类型'int'但参数的类型为'NSInteger'(又名'long')
and Xcode suggests to change %d
to %ld
. 和Xcode建议将
%d
更改为%ld
。
However, it only works for either 32-bit or 64-bit target, as NSInteger
is: 但是,它仅适用于32位或 64位目标,因为
NSInteger
是:
#if __LP64__ || (TARGET_OS_EMBEDDED && !TARGET_OS_IPHONE) || TARGET_OS_WIN32 || NS_BUILD_32_LIKE_64
typedef long NSInteger;
typedef unsigned long NSUInteger;
#else
typedef int NSInteger;
typedef unsigned int NSUInteger;
#endif
What's the best way to kill the warning, for both 32-bit and 64-bit targets? 对于32位和64位目标,杀死警告的最佳方法是什么?
Follow the instructions in Apple's 64-Bit Transition Guide . 按照Apple的64位过渡指南中的说明进行操作 。
For an NSInteger
, use %ld
and cast the value to long
. 对于
NSInteger
,使用%ld
并将值NSInteger
为long
。
[d appendFormat:@"precedence:%ld, ", (long)precedence];
Try this 试试这个
UPD: UPD:
NSInteger precedence = [self operatorPrecedence];
[d appendFormat:@"precedence:%ld, ", (long)precedence];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.