Example:
/* lib.c */
#include <stdio.h>
int f1(int a)
{
printf("%d\n", a);
return 0;
}
/* t3.c */
int main()
{
f1();
return 0;
}
gcc -c -o lib.o lib.c && gcc t3.c lib.o && ./a.exe
t3.c: In function 'main':
t3.c:3:2: warning: implicit declaration of function 'f1' [-Wimplicit-function-declaration]
3 | f1();
| ^~
1
clang -c -o lib.o lib.c && clang t3.c lib.o && ./a.exe
t3.c:3:2: warning: implicit declaration of function 'f1' is invalid in C99 [-Wimplicit-function-declaration]
f1();
^
1 warning generated.
1
Questions:
- Why this even compiles (i.e.
a.exeis generated)? - Why there is no linker error like
error: too few arguments to function call f1, expected 1, have 0? - Is it a constraint violation?