xcode 在 iOS 和 OSX 上使用 unsigned int 和 unsigned long 编译 NSLog 没有警告
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14349844/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Compile NSLog with unsigned int and unsigned long on iOS and OSX without a warning
提问by hanno
On iOS NSUInteger
is a unsigned int
, on OSX it is a unsigned long
. How can I make a print statement like
在 iOS 上NSUInteger
是一个unsigned int
,在 OSX 上它是一个unsigned long
. 我怎样才能做出像这样的打印声明
NSLog(@"Array has %d elements.",[array count]);
compile on both platforms without a warning? I can of course use an #ifdef #else #endif
construct but that will add 4 lines of code. I could also cast the return value to unsigned int. Is there a shorter solution?
在没有警告的情况下在两个平台上编译?我当然可以使用一个#ifdef #else #endif
构造,但这会增加 4 行代码。我也可以将返回值转换为 unsigned int。有更短的解决方案吗?
回答by danh
How about a cast up to the larger of the two?
铸造到两者中较大的一个怎么样?
NSLog(@"Array has %ld elements.",(unsigned long)[array count]);
No warning in iOS, and I think it's a no-op in OSX.
在 iOS 中没有警告,我认为它在 OSX 中是空的。
回答by Nguy?n Kh?c Hoàng
How about a cast up to the larger of the two?
铸造到两者中较大的一个怎么样?
NSLog(@"Array has %ld elements.",(unsigned long)[array count]);
No warning in iOS, and I think it's a no-op in OSX.