Deutsch   English   Français   Italiano  
<875xnvxdcm.fsf@nosuchdomain.example.com>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith Thompson <Keith.S.Thompson+u@gmail.com>
Newsgroups: comp.lang.c
Subject: Re: question about linker
Date: Sat, 07 Dec 2024 15:50:01 -0800
Organization: None to speak of
Lines: 66
Message-ID: <875xnvxdcm.fsf@nosuchdomain.example.com>
References: <vi54e9$3ie0o$1@dont-email.me> <vila9j$3j4dg$1@dont-email.me>
	<vin4su$49a6$1@dont-email.me> <vin95m$5da6$1@dont-email.me>
	<vinh3h$7ppb$1@dont-email.me> <vinjf8$8jur$1@dont-email.me>
	<vip5rf$p44n$1@dont-email.me> <viprao$umjj$1@dont-email.me>
	<viqfk9$13esp$1@dont-email.me> <viqhmn$131h8$3@dont-email.me>
	<visbmp$1ks59$1@dont-email.me> <visgs7$1mgdb$1@dont-email.me>
	<viv5ve$2dqir$1@dont-email.me> <vivggi$2gkth$1@dont-email.me>
	<vj1r8n$35lal$1@dont-email.me> <vj1uge$36ugq$1@dont-email.me>
	<vj22ce$37g4b$1@dont-email.me> <vj263c$396ln$1@dont-email.me>
	<vj2d21$3aqf3$1@dont-email.me> <vj2e34$3b1j8$1@dont-email.me>
	<87msh7xf19.fsf@bsb.me.uk>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Sun, 08 Dec 2024 00:50:23 +0100 (CET)
Injection-Info: dont-email.me; posting-host="a2786d5d7eda6e71f287de5e917519d7";
	logging-data="3570241"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1871PZovoMaroJ4YxiPbchS"
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:08UAUWer4i+j1G2g6Xzwr5qXHy4=
	sha1:kV8LUeoGpRefnhlNDebgPn3k9Vo=
Bytes: 3583

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.com
void Void(void) { Void(); } /* The recursive call of the void */