So today I figured (for the first time admittedly) that int foo()
is in fact different from int foo(void)
in that the first one allows any
First, take int foo()
. This form is a function declaration that does not provide a prototype - that is, it doesn't specify the number and types of its arguments. It is an archaic form of function declaration - it's how functions were originally declared in pre-ANSI C. Such a function however does have a fixed number and type of arguments - it's just that the declaration doesn't tell the compiler what it is, so you are responsible for getting it right where you call the function. You declare such a function with arguments like so:
int foo(a, b)
int a;
char *b;
{
return a + strlen(b);
}
This form of function declaration is now obsolete.
int foo(void)
is a modern declaration that provides a prototype; it declares a function that takes no arguments. int foo(int argc, ...)
also provides a prototype; it declares a function that has one fixed integer argument and a variable argument list.