Sujet : Re: question about linker
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.cDate : 08. Dec 2024, 00:50:01
Autres entêtes
Organisation : None to speak of
Message-ID : <875xnvxdcm.fsf@nosuchdomain.example.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
User-Agent : Gnus/5.13 (Gnus v5.13)
Ben Bacarisse <
ben@bsb.me.uk> writes:
[...]
I've always wondered why prototypes in C did not simply use the existing
syntax for declarations. After all, it was right there in K&R C, just
outside the parentheses:
>
f(m, n, s)
int m, n;
char *s;
{ ... }
>
could have become
>
f(int m, n; char *s)
{ ... }
>
rather than
>
f(int m, int n, char *s)
{ ... }
>
Does anyone know if there even /was/ a reason?
The ANSI C Rationale doesn't provide any illumination on this point.
Function prototypes were borrowed from C++, as I recall, so it might
be mentioned in Stroustrup's "The Design and Evolution of C++".
(I have a paper copy, but it's inaccessible.)
For consistency with existing declaration syntax, there should
probably be a semicolon after each declaration, including the
last one:
void func(int arg;);
but an exception to omit the semicolon before the ")" would not have
been unreasonable. (Struct members follow declaration syntax more
closely, but unlike function declarations they're commonly written on
multiple lines and they're enclosed in {} rather than ().)
One weak argument for the existing syntax is that the use of commas
between parameter declarations mirrors the use of commas between
arguments in a call.
But functions with multiple parameters of the same type aren't so
common that allowing them to be grouped would be all that much of
an advantage. And the syntax wouldn't match exactly anyway, since
many kinds of declarations aren't allowed within in a prototype
and parameter declarations can't have initializers. (Though the
latter could be used for default values.)
And even in ordinary declarations, a common style guideline is to
use a single declaration for each declared entity, for example
int a;
int b;
rather than
int a, b;
or especially
int x;
int *y;
rather than
int x, *y;
-- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.comvoid Void(void) { Void(); } /* The recursive call of the void */