3 ms·
int main() is not a prototype. int main(void) is a prototype. int main() declares main with an unknown (at this point) but fixed number of arguments (i.e., non-
by tom_mellior 9y ago
int main() is not a prototype. int main(void) is a prototype. int main() declares main with an unknown (at this point) but fixed number of arguments (i.e., non-variadic). Callers must guess the correct number and types of arguments, the compiler does not enforce anything. In contrast, int main(void) declares main with exactly 0 arguments, to be enforced by the compiler.
For main it doesn't matter much since usually you don't call it yourself, but consider:
int f(); // no arguments, apparently
int g(int a, int b, int c) {
return f(a) + f(b, c); // at least one of these is fishy...
}
int f(double d) { // oh, the caller guessed wrong. twice.
return (d != 0.0 ? 0 : 1);
}
GCC and Clang do not complain about this program even with -Wall (they do with -Wstrict-prototypes).