如何解决错误:“snprintf”的冲突类型

时间:2012-10-29 10:30:25

标签: compiler-errors osx-lion xcode4.5 llvm-gcc llvm-clang

在我的应用程序中,我使用 Compiler for C / C ++ / Objective-C Apple LLVM编译器4.1 用于模拟器。 对于模拟器,这是有效的。当我为Device i编译相同的代码时,编译器for C / C ++ / Objective-C LLVM GCC 4.2。这次我在stdio.h中收到错误“冲突类型为“sprintf”“。

我使用的是Mac OS x 10.7.4 Xcode 4.5(iOS 6)

这在(Mac OS x 10.7.4& Xcode 4.2.3(iOS 5))&& (Mac OS x 10.6.8& Xcode 3.2.3(iOS 4))。

LLVM编译器的iOS 5和iOS 6有什么区别。请帮帮我吗?

1 个答案:

答案 0 :(得分:1)

在使用数据类型NSIntegerNSUInteger时,在Mac OS X下编译通用应用时,我看到此警告:

NSInteger thing = 7;
NSLog(@"Thing is %ld", thing);

这将在64位下工作,但在32位下发出警告(提示; iOS使用32位架构)。

(丑陋)解决方案是在这种情况下强制thinglong

NSLog(@"Thing is %ld", (long)thing);

哪个都可以在任何地方使用。

这比以下更好:

#ifdef __x86_64
NSLog(@"Thing is %ld", thing);
#else
NSLog(@"Thing is %d", thing);
#endif