Path: ...!news.nobody.at!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Thiago Adams 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 11:26:58 -0300 Organization: A noiseless patient Spider Lines: 73 Message-ID: References: <87wmlzvfqp.fsf@nosuchdomain.example.com> <87h6d2uox5.fsf@nosuchdomain.example.com> <20240707164747.258@kylheku.com> <877cdur1z9.fsf@bsb.me.uk> <871q42qy33.fsf@bsb.me.uk> <87ed82p28y.fsf@bsb.me.uk> <87r0c1nzjj.fsf@bsb.me.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Wed, 10 Jul 2024 16:26:59 +0200 (CEST) Injection-Info: dont-email.me; posting-host="4bc8f9fdbdf5d2cbf448e07f7b72ce8f"; logging-data="2048923"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Uev6DnQbJOb/1CD+Pjsn23eKCIqk3hOQ=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:myHZ6NyGuFfwXdij14lCAfQoIKM= Content-Language: en-US In-Reply-To: <87r0c1nzjj.fsf@bsb.me.uk> Bytes: 4074 On 10/07/2024 10:32, Ben Bacarisse wrote: > bart writes: > >> On 10/07/2024 00:35, Ben Bacarisse wrote: >>> bart writes: >>> >>>> On 09/07/2024 18:22, Ben Bacarisse wrote: >>>>> bart writes: >>>>> >>>>>> 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. >>>>> An address value is passed by value. C has only one parameter passing >>>>> mechanism. You can spin it as much as you like, but C's parameter >>>>> passing is simple to understand, provided learner tune out voices like >>>>> yours. >>>> >>>> Little about C's type system is simple. >>> Parameter passing is relatively simple though since there is only one >>> mechanism -- pass by value. >> >> Except when it comes to arrays. > > The oddity is that, in C, one can't pass arrays to functions at all. > That is one of the quirks that people learning C need to learn. It does > not alter the fact that there is only parameter passing mechanism -- by > value. > > Your plan, of course, is to take that one place where C is relatively > simple and complicate by pretending that C as pass by reference as well > as by value. > GCC and clang have warnings if you use sizeof of the "array" argument. void f(int a[]) { int i = sizeof(a); // } "sizeof on array function parameter will return size of 'int *' instead of 'int[]' [-Wsizeof-array-argument]" But GCC and CLANG does not complain if we do void f(int a[]) { a = 0; } In cake I will have warnings for both cases.