What do errors that conflict with types mean?

I got an error saying “error: conflicting types for“ ____. ”What does this mean?

+3
source share
4 answers

Quickfix:

Make sure your functions are declared once and only once before calling them. 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; }

Possible causes of the error

  • Function called before declaration
  • A specific function overrides the function declared in the included header.
  • The function was defined twice in one file
  • Declaration and definition do not comply
  • Conflict declaration in included headers

What is really going on

error: conflicting types for ‘foo’ , .

, , , , :

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

, 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;}
     ^

,

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

'redefinition':

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;}
        ^

, error: conflicting types for ‘foo’?

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

.

foo() main, foo of int foo(). , , , ( ).

, , , C (, , Objective-C) , . , , , , . , C99.

, , , .

+11

, " _" . :

stdio.h

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] = '\0';
return i;

}

"getline" "getlinexxx" gcc :

int getlinexxx (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] = '\0';
return i;

}

+3

What type of data is ___?

I assume that you are trying to initialize a type variable that cannot accept the initial value. How to sayint i = "hello";

0
source

If you are trying to assign it from a call that returns an NSMutableDictionary, this is probably your problem. Posting a line of code will definitely help diagnose warnings and errors in it.

0
source

Source: https://habr.com/ru/post/1713180/


All Articles