Is it necessary to declare a variable before using it if the compilation works anyway ?
/* hello-world.c */
#include <stdio.h>
int main(void) {
printf("Hello World!\n");
printf("1 + 2 is: %d\n", sum(1, 2));
return 0;
}
/* sum.c */
int sum(int a, int b) {
return a + b;
}
I compile these code with gcc hello-world.c sum.c
and clang hello-world.c sum.c
,
both got a warning: implicit declaration of function 'sum'
but compiled the a.out.
Is there any case proving it's absolutely necessary to declare before using in C?
(edit: Here, i mean the function prototype, if there is any confusion)