C++ and ANSI C
Guy Harris
guy at auspex.auspex.com
Sat May 6 05:25:57 AEST 1989
>> 1. "extern foo();" means (so to speak) "extern foo(...);" in ANSI C and
>> "extern foo(void);" in C++
>
> Number 1 is incorrect since C++ uses '...' to indicate that the number
>and type of arguments is unknown. The void keyword in ANSI C indicates
>that the function takes no arguments. No arguments in the prototype in
>C++ means that there are no arguments.
Uhh, that's what he *said*. ANSI C *also* uses "..." to indicate that
the number and type of arguments (following a certain argument) is
unknown. The "following a certain argument" is relevant - the December
7, 1988 draft indicates that the ellipsis must follow a comma, which
follows an argument; this may be what the "so to speak" indicates. "The
empty list in a function declarator that is not part of a function
definition specifies that no information about the number or types of
the parameters is supplied," so "extern foo();" is equivalent to what
"extern foo (...);" would mean if it were allowed.
"No arguments in the prototype in C++ means that there are no arguments"
is equivalent to "'extern foo();; means ... 'extern foo (void);' in
C++"; according to my copy of S ("S" being a construct whose meaning is
determined by analogy to "K&R" :-)), under "15.3 Anachronisms", "The
keyword 'void' may be used to indicate that a function takes no
arguments, thus '(void)' is equivalent to '()'" (so to speak;
presumably,
() fprintf(stderr, "Doom, defeat, and despair!\n");
is not equivalent to
(void) fprintf(stderr, "Doom, defeat, and despair!\n");
:-)).
More information about the Comp.lang.c
mailing list