Thursday, June 12, 2008

Function type checking in C

Put all the following 3 files in a directory. Run gcc *.c. The compilation will succeed. And running the resulted excecutable file will print I am here, man!. Run g++ *.c The compilation will fail. The reason is that during linking, C only check function names. But C++ check function type.
1. caller.c

#include "callee.h"
int main(void) {
foo();
}

2. callee.h

int foo(void);

3. callee.c

#include
void foo(int v) {
printf( "I am here, man!" );
}

No comments: