Path: ...!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: Tue, 20 Aug 2024 00:33:38 +0100 Organization: A noiseless patient Spider Lines: 141 Message-ID: <87a5h8qe99.fsf@bsb.me.uk> References: <20240712154252.00005c2f@yahoo.com> <86o7717jj1.fsf@linuxsc.com> <20240717163457.000067bb@yahoo.com> <86a5hep45h.fsf@linuxsc.com> <87y14xsvnh.fsf@bsb.me.uk> <87sev5s51s.fsf@bsb.me.uk> <87wmkdqt2t.fsf@bsb.me.uk> <87le0tqoyg.fsf@bsb.me.uk> MIME-Version: 1.0 Content-Type: text/plain Injection-Date: Tue, 20 Aug 2024 01:33:41 +0200 (CEST) Injection-Info: dont-email.me; posting-host="b32b2664ce533497fd23ef21abd144c0"; logging-data="3228042"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+xjJt0vRcYjbWbzb8fzxUz+bTntUQOzak=" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:EFvm04v/xZnNIFeCnBnlA/T4LYU= sha1:PVULaQgKYDP8qWwm+R3TOV1AL0c= X-BSB-Auth: 1.73963644d7772edd2d86.20240820003338BST.87a5h8qe99.fsf@bsb.me.uk Bytes: 6776 Bart writes: > On 19/08/2024 02:30, Ben Bacarisse wrote: >> Bart writes: >> >>> On 19/08/2024 01:01, Ben Bacarisse wrote: >>>> Bart writes: >>>> >>> >>>>> You or he would have to go into more detail, such as an actual example, to >>>>> demonstrate whatever it is that you think is wrong about passing a pointer >>>>> argument by-reference. >>>> No one has said any such thing, so I can't see how any more detail could >>>> help. I suspect you've lost track of the point being made. >>> >>> Probably, and perhaps not just me! But I'd still quite like to know exactly >>> what it is that is marked as 'disallowed'. >> I don't know how to explain it any better. If you really want to know, >> maybe you could say what /you/ think was incorrectly marked as >> disallowed so I can see how you were interpreting the table. > > I think I already said that several times! > > But I need to use concrete code, and there is no existing mainstream > language with pass-by-reference that is simple enough to use for such > examples. Except for mine and that is not acceptable here. > > So I'll use an extended C where a '&' in front of a parameter's base-type > marks it as pass-by-reference. > > First an example written in standard C: > > #include > > void F(int* p) { > printf("%d\n", *p); > ++p; > } > > int main(void) { > int A[] = {10,20,30}; > int* p = &A[0]; > > F(p); > printf("%d\n", *p); > } > > This passes a normal pointer. The output is 10 10 from both printfs, > because the ++p within F does not affect the original pointer in 'main'. > > Now the same program, but using pass-by-reference for 'p'; I won't show the > whole thing, as the program looks exactly the same except for this line: > > void F(&int* p) { > > The output should now be 10 20 (as verified using my language; if > interested, that is shown below, and below that is the standard C that > might be generated by a transpiler from this fantasy C). > > So this is passing a pointer, by reference, and it is allowed! I can't imagine why you though this was what either Tim or I were talking about, but if that is genuinely what you thought he was saying was "disallowed" so be it. We could spend ages arguing about how you could possibly have thought this (especially as you wrote the original example), but nothing will be gained by doing that. >> Or maybe, just maybe, Tim said it for good reason. > > And yet, he continues to be cagey about it, and you're defending him. Just > give me a freakin' example! > > WHAT EXACTLY IS IT THAT IS DISALLOWED? Good grief! You gave the example yourself! I'm not being cagey -- it never occurred to me that you could possibly be thinking about anything other the code you yourself posted and talked about! You: "I'm asking people to compare the first and third functions and their calls, and to see if there's any appreciable difference between them." Your first and third functions: int sum_byvalue(T* A, int n) { int i, sum=0; for (i=0; i