Deutsch English Français Italiano |
<871q42qy33.fsf@bsb.me.uk> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!3.eu.feeder.erje.net!feeder.erje.net!news.in-chemnitz.de!news.swapon.de!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Ben Bacarisse <ben@bsb.me.uk> Newsgroups: comp.lang.c Subject: Re: technology discussion =?utf-8?Q?=E2=86=92?= does the world need a "new" C ? Date: Tue, 09 Jul 2024 18:22:56 +0100 Organization: A noiseless patient Spider Lines: 47 Message-ID: <871q42qy33.fsf@bsb.me.uk> References: <v66eci$2qeee$1@dont-email.me> <v67gt1$2vq6a$2@dont-email.me> <v687h2$36i6p$1@dont-email.me> <871q48w98e.fsf@nosuchdomain.example.com> <v68dsm$37sg2$1@dont-email.me> <87wmlzvfqp.fsf@nosuchdomain.example.com> <v6ard1$3ngh6$4@dont-email.me> <v6b0jv$3nnt6$1@dont-email.me> <87h6d2uox5.fsf@nosuchdomain.example.com> <v6d779$6rk5$2@dont-email.me> <v6e76u$c0i9$1@dont-email.me> <v6esqm$fian$2@dont-email.me> <v6f7vg$hgam$1@dont-email.me> <20240707164747.258@kylheku.com> <v6gl83$s72a$1@dont-email.me> <v6h8ao$ur1v$1@dont-email.me> <v6jhk3$1drd6$1@dont-email.me> <v6jiud$1dsjb$1@dont-email.me> <877cdur1z9.fsf@bsb.me.uk> <v6joi4$1epoj$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain Injection-Date: Tue, 09 Jul 2024 19:22:57 +0200 (CEST) Injection-Info: dont-email.me; posting-host="3bc602097df9bef4fe534cf857153f79"; logging-data="1549294"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+cu/h2EOvI3HyALLykR9+mHv3wIsV65ZQ=" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:aHGDxRwqrvCa+YFCp0wPDfGWISA= sha1:b5Vma1BE6wKTxxHKeakwbvxZyj4= X-BSB-Auth: 1.84ebe6aa0a370da19479.20240709182256BST.871q42qy33.fsf@bsb.me.uk Bytes: 3417 bart <bc@freeuk.com> writes: > On 09/07/2024 16:58, Ben Bacarisse wrote: >> bart <bc@freeuk.com> 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. >> void F(int a[20]) ... declares a to be of type int *. Feel free to rail >> about that as much as you like but that is what that syntax means. >> The x in F(x) is converted to a pointer to x[0] since the x is not an >> operand of &, sizeof etc. F(x) passes a pointer by value. F receives a >> pointer value in a. >> >>> Although the type of 'a' inside 'F' will be int* rather than >>> int(*)[20]. >> No. a is of type int *. > > And that is different 'int*' how, about from having an extra space which C > says is not signigicant in this context? Sorry, I missed what you wrote. I don't know why even brought up int (*)[20] but I thought you were saying that was the type of a. -- Ben.