如何处理 Xcode 警告“没有以前的函数原型......"? [英] How to handle the Xcode warning "no previous prototype for function..."?
问题描述
此警告在某些第三方库中大量出现.
This warning is popping up a bunch in some third party libraries.
有没有办法在不修改代码的情况下处理它(例如忽略警告)?
Is there a way to handle it without modifying the code (e.g. ignore the warning)?
如果我必须修改代码来修复它,我该怎么做?
If I have to modify the code to fix it how do I do it?
这是导致警告的代码块之一:
Here's one of the code blocks that's causing a warning:
BOOL FBIsDeviceIPad() {
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 30200
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
return YES;
}
#endif
return NO;
}
推荐答案
通常对于这样的警告,您可以在文件顶部定义一个函数原型,例如:
Usually with warnings like this you can just define a function prototype at the top of your file, for instance:
BOOL FBIsDeviceIPad();
但是在 C 中的一个方法在大括号之间没有任何内容,即 ()
实际上意味着有任意数量的参数.相反,定义应该变成 (void)
来表示无参数:
But in C a method with nothing between the braces, i.e. ()
actually implies there are an arbitrary number of parameters. Instead the definition should become (void)
to denote no parameters:
BOOL FBIsDeviceIPad(void);
...
BOOL FBIsDeviceIPad(void) {
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 30200
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
return YES;
}
#endif
return NO;
}
这篇关于如何处理 Xcode 警告“没有以前的函数原型......"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!