函数的隐式声明 - C99

发布于 2024-11-24 05:11:01 字数 214 浏览 1 评论 0原文

我目前使用的是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

丑疤怪 2024-12-01 05:11:01

当我用 DLog 全局替换 NSLog 时遇到了这个问题。我愚蠢地包含了这些

#define DLog(...) NSLog(...

语句,所以我最终

#define DLog(...) DLog(...

导致了警告和链接器错误。

I had this problem when I did a global replace of NSLog with DLog. I foolishly included the

#define DLog(...) NSLog(...

statements, so I ended up with

#define DLog(...) DLog(...

which caused the warnings, and a linker error.

白况 2024-12-01 05:11:01

隐式函数声明是编译器第一次看到用作函数调用的声明(与首先看到原型或函数定义的声明相反)。

显然您的代码使用了 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 the localize macro or the precompilation of headers went south an did not include the localize macro so it was left unexpanded.

乖乖 2024-12-01 05:11:01

我遇到的另一个“愚蠢”错误是我的 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...

琴流音 2024-12-01 05:11:01

我遇到这个问题是因为我不小心导入了 CocoaLumberjack,如下所示:

#import <CocoaLumberjack/DDLog.h>

显然 CocoaLumberjack 团队对代码进行了更多模块化;像 DDLogError 这样的宏现在在它们自己的头文件中单独定义。

我用这个替换了导入语句,错误消失了:

#import <CocoaLumberjack/CocoaLumberjack.h>

I had this problem because I accidentally imported CocoaLumberjack like this:

#import <CocoaLumberjack/DDLog.h>

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:

#import <CocoaLumberjack/CocoaLumberjack.h>
迟月 2024-12-01 05:11:01

就我而言,只有一个文件出现此错误。结果我将它添加到了项目的测试目标成员资格中(在右侧的文件检查器中)。

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文