Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: David Brown Newsgroups: comp.lang.c Subject: =?UTF-8?Q?Re=3A_technology_discussion_=E2=86=92_does_the_world_need?= =?UTF-8?B?IGEgIm5ldyIgQyA/?= Date: Fri, 12 Jul 2024 07:53:01 +0200 Organization: A noiseless patient Spider Lines: 39 Message-ID: References: <877cdur1z9.fsf@bsb.me.uk> <871q42qy33.fsf@bsb.me.uk> <87ed82p28y.fsf@bsb.me.uk> <87r0c1nzjj.fsf@bsb.me.uk> <86ikxd8czu.fsf@linuxsc.com> <20240710213910.00000afd@yahoo.com> <865xtc87yo.fsf@linuxsc.com> <87msmnu5e3.fsf@nosuchdomain.example.com> <87frsfu0yp.fsf@nosuchdomain.example.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Fri, 12 Jul 2024 07:53:01 +0200 (CEST) Injection-Info: dont-email.me; posting-host="0d63f29bdb823407c5eda4702e8b85d8"; logging-data="3054375"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/ZZZjyrRgm6+FHMR6nfVoBrFpeah9/yfM=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:jjdSO2HhgRV5lMIHNBK127YI25g= Content-Language: en-GB In-Reply-To: Bytes: 3361 On 11/07/2024 22:36, bart wrote: > On 11/07/2024 21:29, Keith Thompson wrote: >> bart writes: > >>> The language could have helped a little by making this invalid: >>> >>>     int A[20]; >>> >>>     void F(int B[20]) {} >>> >>> The type of B looks just like that of A, but it isn't; the T[N] type >>> is silently changed to T*. The language could insist that you write: >>> >>>     void F(int* B) {} >> >> But it doesn't.  Why should we waste time in comp.lang.c explaining how >> C *could* have been defined?  It's hard enough to explain how it >> actually is defined, especially with your contributions. >> >>> This way, it is far clearer that a pointer is being passed, and 'pass >>> by value' now makes more sense. The way B will be used is now >>> consistent with the same declaration anywhere else. >> >> But that's not C. > > Why isn't it C? Are you trying to blame us for how C is defined? Or is this a serious question about the historical process of design decisions in C? My only guess here - and it is only a guess - is it goes back to the way function parameters were written in K&R C before prototypes, and supported because in C, declarations follow usage. You can write B[10] whether you have "int B[20]" or "int * B", so it seems natural that you could use either form when declaring the parameter. (Note that I too would have preferred a different syntax. IMHO it would have been better either to allow passing arrays by value in some way, or not to allow code that /looks/ like it passes arrays.)