Search code examples
cfunction-declaration

Why don't I get a "conflicting types" error when function has no arguments?


In this example i'm getting a Conflicting types error as expected:

#include <stdio.h>

int a(int b);

int a(int *b){
 return 6;
}

int main(){
 return 0;
}

But not in this example:

#include <stdio.h>

int a(int b);

int a(){
 return 6;
}

int main(){
 return 0;
}

Why the second example is compiling fine although the declaration and definition and of a are still different?


Solution

  • Because in C (but not C++), a() declares a function with an unspecified number of parameters. Use a(void) instead.

    See C function with no parameters behavior