An
implicit function is one where the compiler assumes that the function is declared&defined elsewhere. That is, the compiler doesn't know anything more about the function than what it can figure out when you call it.
1 2 3 4 5
|
int main()
{
printf( "Hello world!\n" ); /* printf() !!?? what's that? */
return 0;
}
|
In the example, since
printf() was never declared, the compiler had to try to figure out what kind of function it is. It looks like
void printf( const char* );
We know different, but that is close enough so it works. (Usually. A C program is automatically linked with the actual printf() function.)
Now, if we want to fix the above, we can declare the function properly -- that is,
explicitly:
1 2 3 4 5 6 7
|
int printf( const char*, ... ); /* here the function is explicitly declared */
int main()
{
printf( "Hello world!\n" ); /* now it can be used, since the compiler knows about it */
return 0;
}
|
Keep in mind that the function must still be
defined somewhere. In the case of
printf() it is defined in the standard library that is automatically linked with your C program. For functions you create yourself you must also declare them:
1 2 3 4 5 6 7 8 9 10 11 12
|
void print_sum( int a, int b ); /* explicit declaration */
int main()
{
print_sum( 27, 15 ); /* happy compiler */
return 0;
}
void print_sum( int a, int b ) /* definition */
{
printf( "%d + %d = %d\n", a, b, a + b ); /* implicit function use */
}
|
Hope this helps.