English 中文(简体)
Strange LLVER 警告:以前没有运行原型
原标题:Strange LLVM warning: no previous prototype for function for

如果我错失了原型,XCode(LV)就促使我错失。

no previous prototype for function for exceptionHandler

但是,为什么在下面的法典中需要这些内容?

void exceptionHandler(NSException * exception); // Why this Line is needed?

void exceptionHandler(NSException * exception)
{
    // ....
}

@implementation AppDelegate

- (void) applicationDidFinishLaunching:(UIApplication *)application
{
    NSSetUncaughtExceptionHandler(&exceptionHandler);
...
最佳回答

如果你只要求在本档案中宣布一项功能,则将声明与<编码>static的关键词和警告放在前面。 既然如此,你就重新宣布一项全球职能;理论上,可以从你所处任何地方要求它。 但是,由于您没有原型,没有人要打could。

因此,正如我所理解的那样,警告试图使你澄清你在固定职能与全球职能之间的意图,并阻止你在你只宣布静止职能时宣布全球职能。

问题回答

根据海湾合作委员会手册:

-Wmissing-prototypes (C and Objective-C only)

如果在没有先前的原型申报的情况下界定全球功能,则警告。 即使定义本身提供了原型,也发出这一警告。 目的是发现全球功能,这些功能无法在标题档案中申报。

Clang为海合会的兼容性而借用了这一选择,因为这样做是有益的(我将假定Clang devs就是这样)。

这种选择是存在的,因此,你可以防止 yourself犯可能轻易避免的共同错误。 为了明确/明确起见,它需要明确可见/联系。

In short, you ve asked the compiler to tell you when an unqualified definition does not match a declaration by enabling this option. You should either qualify that as extern and make it usable to others (e.g. put it in a header), or declare it static. If using C++ inline is also an option.

当然,含蓄的可见度是众所周知的,但我通常认为,在这种情景中,这种选择是有用的:

1) I made a typo:

// file.h
extern void MONExceptionHandler(NSException * exception);

and

// file.m
void MONExceptionhandler(NSException * exception) {
  …

2) I should be explicit about the symbol s visibility:

// file.m
static void MONExceptionHandler(NSException * exception) {
  …

3) I forgot to #include the header which declared the function:

// file.h
extern void MONExceptionHandler(NSException * exception);

警告:

// file.m
void MONExceptionHandler(NSException * exception) {
  …

No 警告:

// file.m
#include "file.h"

void MONExceptionHandler(NSException * exception) {
  …

因此,有理性、历史和一些实例——再一次,-Wmissing-prototypesoption<>。 如果你相信自己会残疾,那么就这样做了。 我倾向于明确,让方案能够发现潜在和实际问题,因此我无需人工处理。

我认为,这对于C++代码最为有用。 例如,我有头盔。

class MyClass {
public:
    void hello();
};

页: 1

void hello() {
    cout << "hello";
}

你们会看到这一警告,因为没有职能模型, 避免了(hello)。 如果正确执行,

void MyClass::hello() {
    cout << "hello";
}

因此,这一警告确保你履行你所了解的职能(不误用名称或不同的论据格式)。

这一警告提醒大家,你可以采用上述另一种方法。 在C,声明/执行令想到很多东西,使你能够接触到的东西或你能够掌握的东西有所区别。





相关问题
How to change out-of-focus text selection color in Xcode?

Okay, I ll bite. I ve got really pleasant code/window colors set up in Xcode. Ordinarily, my selection color is very visible. When I am doing a project search and iterating through the results, ...

Iphone NSTimer Issue

Hi I am new to objective c. I am trying to make an app for iphone. I have a button on my view, and the click on which the function playSound is called. This is working properly. It does plays the ...

Include a .txt file in a .h in C++?

I have a number of places where I need to re-use some template code. Many classes need these items In a .h could I do something like: #include <xxx.txt> and place all of this code in the ....

Iterating over string/strlen with umlauted characters

This is a follow-up to my previous question . I succeeded in implementing the algorithm for checking umlauted characters. The next problem comes from iterating over all characters in a string. I do ...

Xcode open two editor windows with same file

Is it possible to open the same file in two separate windows in Xcode. I can open a file in one window and the same file in the main Xcode editor window, but I wanted two separate fulltime editor ...

Forcing code signing refresh in Xcode

In our environment, we share resources across multiple projects and platforms. When building for iPhone, only a subset of those resources are needed. Since that subset is still considerable, we have ...