Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Tim Rentsch Newsgroups: comp.lang.c Subject: Re: question about linker Date: Wed, 11 Dec 2024 08:52:54 -0800 Organization: A noiseless patient Spider Lines: 70 Message-ID: <86cyhyi2l5.fsf@linuxsc.com> References: <87msh7xf19.fsf@bsb.me.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Date: Wed, 11 Dec 2024 17:52:57 +0100 (CET) Injection-Info: dont-email.me; posting-host="5a9238e0228d2242d35dbd42b74f50a6"; logging-data="1725127"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+nL/xAbpfxcse0u1Xgde3bBbNsUkL1iHY=" User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux) Cancel-Lock: sha1:+Sm5hwnZFUFWvITXYwFccz071Vg= sha1:R4LyKn+otUNCgAF7697JmjZr8Jo= Ben Bacarisse writes: > Bart writes: > >> On 07/12/2024 21:00, David Brown wrote: >> >>> >> >> You mean that /real/ example where a function needed a type written 6 times >> instead of once? OK. > > 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? My speculation follows. Prototypes in C came from C++. The language that became C++ started pretty early, before 1980 IIRC. To add types to function parameters it would have been natural to simply add a type before the named parameter. Of course to be more flexible a full declarator rather than just a type name should be allowed. That change should be easy to make in a C grammar and parser. The idea of using multi-declarator declarations might not have occurred to the pre-C++ language designer(s); or it may have been judged to need too much effort or not be necessary (or add enough value). Also there is another difference between declarations given in a block/file scope and declarations given in a prototype scope: in one case the order of declarators doesn't matter but in the other case it does. Furthermore there is the question of what to do for function declarations, as opposed to definitions, where parameter names are not given, but just types. Assuming all that was done before the C standardization effort really got rolling, which I think is a distinct possibility, the most likely decision would be simply to adopt the existing C++ syntax wholesale, and not consider changing it. Anyway that is my guess. If the question were being considered anew, I would be inclined to come down on the side of keeping the one-parameter-only form, and not allowing multiple parameters to share a single type name. There doesn't seem to be much benefit in allowing more than one declarator per type name; I think the strongest argument is syntactic consistency with block/file/struct scope declarations, but those contexts aren't quite the same as prototype scope (for different reasons in the different cases). If there is no significant benefit, simpler is better, and consistency be damned. One change I would like to see made, and to have been made, is to allow a trailing comma in function declarations, definitions, and calls. A smaller change, and a larger benefit, would give a win here. At least that is my thinking on the matter.