ios “没有以前的函数原型”警告
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7076345/
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
"No previous prototype for function" warning
提问by Wang Yanchao
i use shareKit to myself program .
我将 shareKit 用于自己的程序。
but in the FBConnectGlobal, there are some warning,
但是在FBConnectGlobal中,有一些警告,
NSMutableArray* FBCreateNonRetainingArray() {
CFArrayCallBacks callbacks = kCFTypeArrayCallBacks;
callbacks.retain = RetainNoOp;
callbacks.release = ReleaseNoOp;
return (NSMutableArray*)CFArrayCreateMutable(nil, 0, &callbacks);
}
like this method, it warning:"No previous prototype for function FBCreateNonRetainingArray"
像这个方法一样,它警告:“函数 FBCreateNonRetainingArray 没有以前的原型”
回答by daveswen
According to c standard, declaring the prototype as
根据c标准,将原型声明为
NSMutableArray* FBCreateNonRetainingArray(void);
// ---------------> ^^^^
// Yes, with the void as the parameter
solves the issue.
解决了这个问题。
回答by Derek Bredensteiner
To clarify Eric Dchao's answer above, someone at facebook apparently didn't put a "static" in front of that BOOL?
为了澄清上面 Eric Dchao 的回答,facebook 上的某个人显然没有在那个 BOOL 前面放一个“静态”?
Anyways, changing from this
无论如何,从这里改变
BOOL FBIsDeviceIPad() {
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 30200
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
return YES;
}
#endif
return NO;
}
to this
对此
static BOOL FBIsDeviceIPad() {
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 30200
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
return YES;
}
#endif
return NO;
}
fixed it for me.
为我修好了。
回答by fannheyward
UPDATE: Disable warnings is not a good solution, check @Derek Bredensteiner's answer.
更新:禁用警告不是一个好的解决方案,请查看@Derek Bredensteiner 的回答。
In Xcode 4, go to your project's Build Settings. Search for "prototype". There should be an option called "Missing Function Prototypes"; disable it.
在 Xcode 4 中,转到项目的 Build Settings。搜索“原型”。应该有一个选项叫做“Missing Function Prototypes”;禁用它。
via here
通过这里
回答by basicthinker
Is it a globalfunction? Add "static" if it is only used in the current file.
它是一个全局函数吗?如果仅在当前文件中使用,则添加“静态”。
The possible reason is as below:
可能的原因如下:
no previous prototype for `foo'
`foo' 没有以前的原型
This means that GCC found a global function definition without seeing a prototype for the function. If a function is used in more than one file, there should be a prototype for it in a header file somewhere. This keeps functions and their uses from getting out of sync
这意味着 GCC 在没有看到函数原型的情况下找到了一个全局函数定义。如果一个函数在多个文件中使用,那么在某个头文件中应该有它的原型。这可以防止函数及其用途不同步
If the function is only used in this file, make it static to guarantee that it'll never be used outside this file and document that it's a local function
如果该函数仅在此文件中使用,请将其设为静态以确保永远不会在此文件之外使用它并记录它是一个本地函数