函数的隐式声明 - C99
我目前使用的是 Xcode 4,在我的 .pch 文件中我有这个宏: #define localize(s) NSLocalizedString((s), nil)
。
当我尝试在某些 .m 文件中使用此宏时,我收到此警告:函数“localize”的隐式声明在 C99 中无效
。
这段代码编译没有问题,但是我该如何解决这个问题以免收到警告?
I am currently using Xcode 4, and in my .pch file I have this macro:#define localize(s) NSLocalizedString((s), nil)
.
When I try to use this macro in some .m file, I receive this warning: Implicit declaration of function 'localize' is invalid in C99
.
This code compiles without a problem, but how can I fix this so I don't get a warning?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
当我用 DLog 全局替换 NSLog 时遇到了这个问题。我愚蠢地包含了这些
语句,所以我最终
导致了警告和链接器错误。
I had this problem when I did a global replace of NSLog with DLog. I foolishly included the
statements, so I ended up with
which caused the warnings, and a linker error.
隐式函数声明是编译器第一次看到用作函数调用的声明(与首先看到原型或函数定义的声明相反)。
显然您的代码使用了
localize(foo)
但宏定义不可见。可能的原因:您忘记#include
包含localize
宏的文件,或者标头的预编译出错,没有包含localize
宏,因此它没有展开。Implicit function declarations are those that the compiler sees the first time used as a function call (as opposed to those where a prototype or the function definition is seen first).
Apparently your code used
localize(foo)
but the macro definition was not visible. Possible reasons: you forgot to#include
the file containing thelocalize
macro or the precompilation of headers went south an did not include thelocalize
macro so it was left unexpanded.我遇到的另一个“愚蠢”错误是我的 DLog 是在 iOS 目标的前缀标头中定义的,因此我也必须将其复制到 OSX 目标的前缀......
Another "foolish" mistake I ran into was the fact that my DLog was defined in the prefix header of the iOS target, so I had to copy it over to the prefix of the OSX target, as well...
我遇到这个问题是因为我不小心导入了 CocoaLumberjack,如下所示:
显然 CocoaLumberjack 团队对代码进行了更多模块化;像
DDLogError
这样的宏现在在它们自己的头文件中单独定义。我用这个替换了导入语句,错误消失了:
I had this problem because I accidentally imported CocoaLumberjack like this:
Apparently the CocoaLumberjack team modularized the code some more; and macros like
DDLogError
are now defined separately in their own header file.I replaced the import statement with this and the error went away:
就我而言,只有一个文件出现此错误。结果我将它添加到了项目的测试目标成员资格中(在右侧的文件检查器中)。
In my case only one file was giving this error. Turned out that I added it to the project's tests target membership (in the File Inspector on the right).