xcode '' 的错误类型冲突是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1161012/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 03:06:10  来源:igfitidea点击:

What does error conflicting types for '' mean?

iphonexcode

提问by user134721

i got an error that said "error: conflicting types for '____'. What does that mean?

我收到一条错误消息:“错误:'____' 的类型冲突。这是什么意思?

回答by brice

Quickfix:

Make sure that your functions are declared once and only once before they are called. For example, change:

main(){ myfun(3.4); }
double myfun(double x){ return x; }

To:

double myfun(double x){ return x; }
main(){ myfun(3.4); }

Or add a separate function declaration:

double myfun(double x);
main(){ myfun(3.4); }
double myfun(double x){ return x; }

快速解决:

确保您的函数在调用之前声明一次且仅声明一次。例如,更改:

main(){ myfun(3.4); }
double myfun(double x){ return x; }

到:

double myfun(double x){ return x; }
main(){ myfun(3.4); }

或者添加一个单独的函数声明:

double myfun(double x);
main(){ myfun(3.4); }
double myfun(double x){ return x; }

Possible causes for the error

错误的可能原因

  1. Function was called before being declared
  2. Function defined overrides a function declared in an included header.
  3. Function was defined twice in the same file
  4. Declaration and definition don't match
  5. Declaration conflict in the included headers
  1. 函数在声明之前被调用
  2. 定义的函数覆盖在包含的头文件中声明的函数。
  3. 函数在同一个文件中定义了两次
  4. 声明和定义不匹配
  5. 包含的标头中的声明冲突

What's really going on

到底是怎么回事

error: conflicting types for ‘foo'means that a function was defined more than once with different type signatures.

error: conflicting types for ‘foo'意味着一个函数用不同的类型签名定义了不止一次。

A file that includes two functions with the same name but different return types would throw this error, for example:

包含两个名称相同但返回类型不同的函数的文件会抛出此错误,例如:

int foo(){return 1;}
double foo(){return 1.0;}

Indeed, when compiled with GCC we get the following errors:

事实上,当使用 GCC 编译时,我们会收到以下错误:

foo.c:5:8: error: conflicting types for ‘foo'
 double foo(){return 1.0;}
        ^
foo.c:4:5: note: previous definition of ‘foo' was here
 int foo(){return 1;}
     ^

Now, if instead we had a file with two function definitions with the same name

现在,如果我们有一个包含两个同名函数定义的文件

double foo(){return 1;}
double foo(){return 1.0;}

We would get a 'redefinition' error instead:

我们会得到一个“重新定义”错误:

foo.c:5:8: error: redefinition of ‘foo'
 double foo(){return 1.0;}
        ^
foo.c:4:8: note: previous definition of ‘foo' was here
 double foo(){return 1;}
        ^

Implicit function declaration

隐式函数声明

So why does the following code throw error: conflicting types for ‘foo'?

那么为什么下面的代码会抛出error: conflicting types for ‘foo'

 main(){ foo(); }
 double foo(){ return 1.0; }

The reason is implicit function declaration.

原因是隐式函数声明

When the compiler first encounters foo()in the mainfunction, it will assume a type signature for the function fooof int foo(). By default, implicit functions are assumed to return integers, and the input argument types are derived from what you're passing into the function (in this case, nothing).

当编译器第一次接触foo()main功能,将承担功能的类型签名fooint foo()。默认情况下,假定隐式函数返回整数,并且输入参数类型源自您传递给函数的内容(在这种情况下,什么都没有)。

Obviously, the compiler is wrong to make this assumption, but the specs for the C (and thus Objective-C) language are old, cranky, and not very clever. Maybe implicitly declaring functions saved some development time by reducing compiler complexity back in the day, but now we're stuck with a terrible feature that should have never made it into the language. In fact, implicit declarations were made illegal in C99.

显然,编译器做出这个假设是错误的,但是 C(以及 Objective-C)语言的规范是旧的、古怪的,而且不是很聪明。也许隐式声明函数通过降低编译器的复杂性来节省一些开发时间,但现在我们被困在一个可怕的特性上,它本不应该进入语言。事实上,隐式声明在 C99 中是非法的。

That said, once you know what's going on, it should be easy to dig out the root cause of your problem.

也就是说,一旦您知道发生了什么,就应该很容易找出问题的根本原因。

回答by ebrioloco

it's probably because your function "_" already exists in your library. It happened to me with this function:

这可能是因为您的函数“ _”已存在于您的库中。这个功能发生在我身上:

I was using stdio.h

我正在使用 stdio.h

int getline (char s[ ] , int lim) { int c, i;

int getline (char s[], int lim) { int c, i;

for (i=0; i < lim-1 && (c=getchar())!=EOF && c!='\n'; ++i)
    s[i] = c;
if (c == '\n') {
    s[i] = c;
    ++i;
}
s[i] = '
for (i=0; i < lim-1 && (c=getchar())!=EOF && c!='\n'; ++i)
    s[i] = c;
if (c == '\n') {
    s[i] = c;
    ++i;
}
s[i] = '##代码##';
return i;
'; return i;

}

}

When I changed "getline" to "getlinexxx" and gcc compiled it:

当我将“getline”更改为“getlinexxx”并且gcc编译它时:

int getlinexxx (char s[], int lim) { int c, i;

int getlinexxx (char s[], int lim) { int c, i;

##代码##

}

}

And the problem was gone

问题就解决了

回答by bkritzer

What datatype is '___'?

'___' 是什么数据类型?

My guess is that you're trying to initialize a variable of a type that can't accept the initial value. Like saying int i = "hello";

我的猜测是您正在尝试初始化一个不能接受初始值的类型的变量。喜欢说int i = "hello";

回答by cdespinosa

If you're trying to assign it from a call that returns an NSMutableDictionary, that's probably your trouble. Posting the line of code would definitely help diagnose warnings and errors in it.

如果您尝试从返回 NSMutableDictionary 的调用中分配它,那可能是您的麻烦。发布这行代码肯定有助于诊断其中的警告和错误。