Deutsch   English   Français   Italiano  
<v78af7$1qkuf$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bart <bc@freeuk.com>
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, 17 Jul 2024 12:38:15 +0100
Organization: A noiseless patient Spider
Lines: 74
Message-ID: <v78af7$1qkuf$1@dont-email.me>
References: <v66eci$2qeee$1@dont-email.me> <v6jiud$1dsjb$1@dont-email.me>
 <877cdur1z9.fsf@bsb.me.uk> <v6joi4$1epoj$1@dont-email.me>
 <871q42qy33.fsf@bsb.me.uk> <v6k6i0$1h4d3$1@dont-email.me>
 <87ed82p28y.fsf@bsb.me.uk> <v6m03l$1tf05$1@dont-email.me>
 <87r0c1nzjj.fsf@bsb.me.uk> <v6m716$1urj4$1@dont-email.me>
 <87ikxconq4.fsf@bsb.me.uk> <v6n8iu$24af0$1@dont-email.me>
 <20240711115418.00001cdf@yahoo.com> <v6oamt$2d8nn$1@dont-email.me>
 <v6oct4$2djgq$2@dont-email.me> <v6of96$2ekb0$1@dont-email.me>
 <v6ovfc$2hcpf$1@dont-email.me> <v6p4hf$2icph$1@dont-email.me>
 <v6qgpu$2t6p7$3@dont-email.me> <v6r33m$30grj$1@dont-email.me>
 <20240712154252.00005c2f@yahoo.com> <86o7717jj1.fsf@linuxsc.com>
 <v6ti10$3gru4$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 17 Jul 2024 13:38:15 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="bf2146295ce154b402888450fc1558ab";
	logging-data="1921999"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18F6/yShFpd5r1KSx9JqQi4"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:jPztXE5nbsu/Pwy+irMoUqTRBoE=
In-Reply-To: <v6ti10$3gru4$1@dont-email.me>
Content-Language: en-GB
Bytes: 3910

On 13/07/2024 10:39, BGB wrote:

> But, as I see it, no real point in arguing this stuff (personally, I 
> have better stuff to be doing...).

We all do. But this group seems to be about arguing about pointless 
stuff and you might come here when you want a respite from proper work.

However (here I assume you've gone back to Quake but that other 
interested parties might be reading this), consider the program below.

That sets up an array and then sums its elements by calling 3 different 
functions to do the job:

(1) Using normal C pass-by-value

(2) Using C pass-by-value to emulate call-by-reference

(3) Using fantasy true call-by-reference as it might appear if C had the
     feature

(I'd hoped C++ would run this, but it didn't even like the middle function.)

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. 
There will obviously be a difference in how the A parameter is declared.

---------------------------------------------
#include <stdio.h>

typedef int T;

int sum_byvalue(T* A, int n) {
     int i, sum=0;
     for (i=0; i<n; ++i) sum += A[i];
     return sum;
}

int sum_bymanualref(T(*A)[], int n) {
     int i, sum=0;
     for (i=0; i<n; ++i) sum += (*A)[i];
     return sum;
}

int sum_bytrueref(T (&A)[], int n) {
     int i, sum=0;
     for (i=0; i<n; ++i) sum += A[i];
     return sum;
}

int main(void) {
     enum {N = 10};
     T A[N] = {10,20,30,40,50,60,70,80,90,100};
     int total=0;

     total += sum_byvalue     (A, N);
     total += sum_bymanualref (&A, N);
     total += sum_bytrueref   (A, N);

     printf("%d\n", total);             // would show 1650
}
---------------------------------------------

Find anything? I thought not.

Those findings might suggest that C doesn't need call-by-reference, not 
for arrays anyway. Except that at present you can do this:

     T x=42;
     sum_byvalue(&x, N);

which would not be possible with call-by-reference. Nor with 
sum_bymanualref, but apparently nobody wants to be doing with all that 
extra, fiddly syntax. Better to be unsafe!