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

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

Path: ...!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Janis Papanagnou <janis_papanagnou+ng@hotmail.com>
Newsgroups: comp.lang.c
Subject: =?UTF-8?Q?Re:_technology_discussion_=e2=86=92_does_the_world_need_a?=
 =?UTF-8?Q?_=22new=22_C_=3f?=
Date: Wed, 10 Jul 2024 17:09:56 +0200
Organization: A noiseless patient Spider
Lines: 55
Message-ID: <v6m886$1v629$1@dont-email.me>
References: <v66eci$2qeee$1@dont-email.me> <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> <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>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 10 Jul 2024 17:09:58 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="e2d273f8bd60b235777bd340f7935ea5";
	logging-data="2070601"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18ezbVnpe56oKvgI3OGml0N"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
 Thunderbird/45.8.0
Cancel-Lock: sha1:524mk/7hUP7MGTn1eaaMLGXuvN4=
In-Reply-To: <v6m716$1urj4$1@dont-email.me>
X-Enigmail-Draft-Status: N1110
Bytes: 4023

On 10.07.2024 16:49, bart wrote:
> On 10/07/2024 14:32, Ben Bacarisse wrote:
>>>
>>> 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
> 
> It is not that simple. It is confusing. It is error prone.
> 
> I earlier asked this:
> 
> "So if arrays aren't passed by value in C, and they aren't passed by
> reference, then how the hell ARE they passed?!"

Arrays are not passed to the function; the address if the first array
element is passed as a pointer value to the function.

> 
> I haven't had a reply yet. I still consider arrays in C to be 'passed'
> by a mechanism which is near-indistinguishable from actual
> pass-by-reference.

It can be distinguished. Call by reference means that you provide an
object to the function that can be changed in its environment. In C,
where a pointer to an array is passed, you can (for example) also
pass a 0-pointer value.

> 
> If somebody had proposed adding pass-by-reference for arrays, you'd say
> C doesn't need it, because whatever benefits it might have you, C
> already has!

This is obviously wrong. - You can (to some degree) emulate a reference
mechanism by using pointer values. But "C" doesn't have a mechanism to
pass "by reference". (Note that "pass by reference" is not a colloquial
term like we may colloquially use "reference". It's rather a technical
term with a specific - and I hope quite unique :-) - meaning.)

(For arrays it is (conveniently?) hidden by the language as designed,
but you can still observe it by behavioral side effects.)

There's also another advantage of references; try implementing such
simple things like binary tree operations (including updates) once
with references (in C++) and once with pointers emulating references.
(Or read some basic book about Algorithms and Data Structures where
you typically find such code and can simply study it.)

Janis