I'm a Java programmer,I learnt a little C++ and now I'm studying a little C for my job. I can't understand C behaviour about function declaration/definition and related function calls. From K&R I know that in C (very different from C++) I can call a function that has not been previously declared,and the compiler assumes an implicit declaration of the type:
int main()
{
function(10); // implicit function declaration ( int function() )
}
and I know that such a declaration implies a function that accepts a fixed but indefinite number of arguments of any type (as long as each call is consistent with the others). And I know this is K&R C, before C89, but I want to know how it works as well. Now, I have this test code, I can't understand:
#include <stdio.h>
function();
int main()
{
printf("hello %d",function(1,2,3));
implicit(11,12,32); // implicit function declaration ( implicit() )
}
int implicit(int b)
{
}
function(int a)
{
}
in the case of function
the declaration (return type is assumed to be int,no assumption about the arguments) does match the definition (the compiler issues a warning) but if I call the function with the wrong arguments,it compiles!
Same for the function implicit
.
I can't understand..