Path: ...!feeds.phibee-telecom.net!2.eu.feeder.erje.net!feeder.erje.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: bart Newsgroups: comp.lang.c Subject: =?UTF-8?Q?Re=3A_technology_discussion_=E2=86=92_does_the_world_need?= =?UTF-8?B?IGEgIm5ldyIgQyA/?= Date: Wed, 10 Jul 2024 00:04:40 +0100 Organization: A noiseless patient Spider Lines: 52 Message-ID: References: <871q48w98e.fsf@nosuchdomain.example.com> <87wmlzvfqp.fsf@nosuchdomain.example.com> <87h6d2uox5.fsf@nosuchdomain.example.com> <20240707164747.258@kylheku.com> <877cdur1z9.fsf@bsb.me.uk> <20240709152805.587@kylheku.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Wed, 10 Jul 2024 01:04:39 +0200 (CEST) Injection-Info: dont-email.me; posting-host="ded9e1848a26cfa2c70264cde0490f0f"; logging-data="1653607"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19f7lN5qY6IolLNZUPaMZUz" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:B3guzj7jbjrp+KIftgU6Cd5HM3g= Content-Language: en-GB In-Reply-To: <20240709152805.587@kylheku.com> Bytes: 3256 On 09/07/2024 23:32, Kaz Kylheku wrote: > On 2024-07-09, bart wrote: >> On 09/07/2024 16:58, Ben Bacarisse wrote: >>> bart writes: >>> >>>> Arrays are passed by reference: >>>> >>>> void F(int a[20]) {} >>>> >>>> int main(void) { >>>> int x[20]; >>>> F(x); >>>> } >>> >>> This is the sort of thing that bad tutors say to students so that they >>> never learn C properly. All parameter passing in C is by value. All of >>> it. You just have to know (a) what the syntax means and (b) what values >>> get passed. >> >> The end result is that a parameter declared with value-array syntax is >> passed using a reference rather than by value. >> >> And it does so because the language says, not because the ABI requires >> it. A 2-byte array is also passed by reference. > > In C, arrays are not passed to functions, period. Arrays can be passed by explicit reference: void F(int(*A)[20]) { printf("%zu\n", sizeof(*A)/sizeof((*A)[0])); // shows 20 } That can be called like this: int a[20]; F(&a); Here, an actual array type is involved, which is passed by an actual pointer to array, not a pointer to its elements. > Therefore ABIs do not say anything about array parameters, > (or if they do, it's not in relation to C). That makes a change; most people think that C invented ABIs, which were created in its image. The Win64 ABI talks about aggregate types.