In C99, the compiler will issue a warning if a function is called before its declaration. For example, this will cause a warning:
int sum(const int k) {
return accsum(k, 0);
}
int accsum(const int k, const int acc) {
if (k == 0) {
return acc;
} else {
return accsum(k-1, k + acc);
}
}
int main() {
int x = sum(3);
return 0;
}
The answer I've seen after Googling is declaration is needed so that the compiler can check the parameter types to avoid errors. But why can't the compiler just go find the function definition of accsum before executing accsum when accsum is called from within sum?