Path: ...!2.eu.feeder.erje.net!feeder.erje.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Ben Bacarisse Newsgroups: comp.lang.c Subject: Re: technology discussion =?utf-8?Q?=E2=86=92?= does the world need a "new" C ? Date: Wed, 10 Jul 2024 00:35:57 +0100 Organization: A noiseless patient Spider Lines: 44 Message-ID: <87ed82p28y.fsf@bsb.me.uk> 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> <871q42qy33.fsf@bsb.me.uk> MIME-Version: 1.0 Content-Type: text/plain Injection-Date: Wed, 10 Jul 2024 01:35:58 +0200 (CEST) Injection-Info: dont-email.me; posting-host="4de7691f4ab8416481d0de19b6a8d938"; logging-data="1659305"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18epITPta9QDxyjCVaFG5maXItcqr7uCV4=" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:VR7XLrsV+8mhR8s8AL15JUdsVQQ= sha1:DiTGesvo/2Zio/QJAha9cK9QMvk= X-BSB-Auth: 1.457495354aba8c7fcce5.20240710003557BST.87ed82p28y.fsf@bsb.me.uk Bytes: 3224 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. > You're doing your students a > disservice if you try and hide all the quirks. If. Always with the if. There are lots of things I don't do that would be doing my students a disservice were I to do them. Beautiful spin! -- Ben.