In article <45***********************@free.teranews.com>,
Stephen Sprunk <st*****@sprunk.orgwrote:
>i think, an "empty pair" of parenthesis means a function can take
unlimited number of arguments
>Consider:
void foo();
void bar(void);
void baz() {}
foo is a function that takes an unspecified number of arguments. bar and
baz are both functions that take zero arguments. See the differences?
To be explicit: in pre-ANSI C, function declarations specified only
the return type, not the arguments, and definitions specified the
arguments with a syntax like this:
int main(argc, argv)
int argc;
char **argv;
{
...
So if you see
int foo();
this is an old-style declaration of foo which does not specify the
arguments. It doesn't mean it has an unlimited number, it just doesn't
say anything about it.
The modern way to write it is:
int foo(void);
if it doesn't take any arguments, or (for example):
int foo(int a, double b);
if it takes an int and a double argument.
In modern C, the function definition looks the same as the declaration:
int foo(void)
{
...
but in old-style it would look like:
int foo()
{
...
so the interpretation of the empty parameter list was quite different in
declarations and definitions: in declarations it meant nothing, but in
definitions it meant that there were no arguments. The modern syntax is
more consistent, if not elegant.
Furthermore, it was (and still is in C90) legal to omit the return type
if it's int. So the original example:
main()
{
...
specifies main() as taking no arguments and returning an int.
-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.