如何处理 Xcode 警告“没有以前的函数原型......”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7097660/
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
How to handle the Xcode warning "no previous prototype for function..."?
提问by Christian Schlensker
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;
}
回答by appmattus
Usually with warnings like this you can just define a function prototype at the top of your file, for instance:
通常对于这样的警告,您只需在文件顶部定义一个函数原型,例如:
BOOL FBIsDeviceIPad();
Butin 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 noparameters:
但是在 C 中,大括号之间没有任何内容的方法,即()
实际上意味着有任意数量的参数。相反,定义应该变成(void)
表示没有参数:
BOOL FBIsDeviceIPad(void);
...
BOOL FBIsDeviceIPad(void) {
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 30200
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
return YES;
}
#endif
return NO;
}
回答by bosmacs
In Xcode4, go to your project's Build Settings. Search for "prototype". There should be an option called "Missing Function Prototypes"; disable it. You can also do this to the specific target(s) in question.
在 Xcode4 中,转到项目的 Build Settings。搜索“原型”。应该有一个选项叫做“Missing Function Prototypes”;禁用它。您也可以对相关的特定目标执行此操作。
回答by thomsky
There are no warnings if such a function is defined as inline.
如果将此类函数定义为内联函数,则不会发出警告。
This may suffice as long as your function is optimized for inline use. http://msdn.microsoft.com/en-us/library/1w2887zk.aspx
只要您的函数针对内联使用进行了优化,这可能就足够了。 http://msdn.microsoft.com/en-us/library/1w2887zk.aspx