如何处理 Xcode 警告“没有以前的函数原型...”?
这个警告在一些第三方库中大量出现。
有没有办法在不修改代码的情况下处理它(例如忽略警告)?
如果我必须修改代码来修复它,我该怎么做?
这是导致警告的代码块之一:
BOOL FBIsDeviceIPad() {
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 30200
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
return YES;
}
#endif
return NO;
}
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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果此类函数被定义为内联,则不会出现警告。
只要您的函数针对内联使用进行了优化,这可能就足够了。
http://msdn.microsoft.com/en-us/library/1w2887zk.aspx
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
修复警告的另一种方法是使函数静态,以便它们仅在文件中可见(具体来说,只能在文件的翻译单元内链接)。
似乎此警告的部分用途是,如果您有一个独立函数,您要么希望它在其他实现文件中可用,要么仅在定义它的文件中使用。此警告使您明确该选择,并帮助您了解标头是否与实现存在偏差。
如果您希望它可以在其他实现文件中使用,则应该将其原型放在标头中的某个位置。
如果您希望它只能在此文件中使用,那么它应该是静态的。
Another way of fixing the warning is to make the functions
static
so they're only visible within the file (specifically, can only be linked within the file's translation unit).It seems like part of the use of this warning is that if you have a standalone function, you either want it usable in other implementation files, or only in the file where it's defined. This warning makes you be explicit about that choice, and helps you be aware if the header has diverged from the implementation.
If you want it usable in other implementation files, you should have its prototype in a header somewhere.
If you want it only usable in this file, then it should be static.
通常,对于这样的警告,您可以在文件顶部定义一个函数原型,例如:
But 在 C 中是一个大括号之间没有任何内容的方法,即
()
实际上意味着有任意数量的参数。相反,定义应变为(void)
以表示无参数:Usually with warnings like this you can just define a function prototype at the top of your file, for instance:
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:在 Xcode4 中,转到项目的“构建设置”。搜索“原型”。应该有一个名为“Missing Function Prototypes”的选项;禁用它。您还可以对相关的特定目标执行此操作。
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.