I came across the following difference related to function definition/declaration between C and C++.
In C++ if I call a function before declaring and defining it,I get the error message 'function name is invalid identifier' which is fine for me as it sounds reasonable.
In C with Visual Studio compiler when I compiled the following program I get the error message:
error C2371: 'fun' : redefinition; different basic types
and in gcc-4.3.4 it executed successfully with just this warning:
warning: conflicting types for ‘fun’
Here goes the program:
#include <stdio.h>
int main(){
fun();
return 0;
}
void fun(){
printf("It is fun");
}
So is it fine in C to just call a function and later bother about defining it?! And why the compilers behave differently?