Deutsch   English   Français   Italiano  
<87le2avyd1.fsf@nosuchdomain.example.com>

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

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: Keith Thompson <Keith.S.Thompson+u@gmail.com>
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:18:02 -0700
Organization: None to speak of
Lines: 59
Message-ID: <87le2avyd1.fsf@nosuchdomain.example.com>
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> <20240709152805.587@kylheku.com>
	<v6kfm6$1ier7$1@dont-email.me>
	<87plrmw2fl.fsf@nosuchdomain.example.com>
	<v6kl5v$1j8l7$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Wed, 10 Jul 2024 03:18:02 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="2ff96a67704e58776cf4f9c1dffac965";
	logging-data="1691440"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19i96P4GzBoMR3PkDYlP1JQ"
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:eIjVeXknp378KpEfpuIrvZlGJ2A=
	sha1:NI81p+/4nPGlAXueUCPwH05Jw7w=
Bytes: 3757

bart <bc@freeuk.com> writes:
> On 10/07/2024 00:50, Keith Thompson wrote:
>> bart <bc@freeuk.com> writes:
>> [...]
>>> Arrays can be passed by explicit reference:
>>>
>>>    void F(int(*A)[20]) {
>>>        printf("%zu\n", sizeof(*A)/sizeof((*A)[0]));    // shows 20
>>>    }
>>>
>>> That can be called like this:
>>>
>>>    int a[20];
>>>    F(&a);
>> On the language level, that's passing a pointer to an array object.
>> The pointer itself is passed by value.  Passing a pointer to an array
>> is conceptually no different than passing a pointer to anything else.
>
> I was replying to:
>
>  "In C, arrays are not passed to functions, period."

Which is a correct statement.

[...]

> But notice how C gives exactly the same result as my code that used
> by-reference, even though:
>
>  * C "doesn't pass arrays by reference"
>  * C's F function uses the same parameter type (only & is missing; maybe
>    by-ref is implicit...)
>  * No explicit de-ref is needed inside F
>  * No explicit address-of is needed when calling F

Right.  The C rules that make all this possible have been explained
to you many times.  I won't waste my time explaining them to you
again.  If you were interested in learning, you would read section
6 of the comp.lang.c FAQ.

Yes, some of C's rules make it *look like* arrays are passed by
reference.

> So C behaves exactly as though it passes arrays by-reference, and yet
> it doesn't have pass-by-reference. In fact, C does it without even
> needing to be told!

If you actually believed that C has pass-by-reference for arrays, it
would indicate that you don't understand C.  But you're only pretending
to believe it.

If C had pass-by-reference for arrays, then presumably you could obtain
the size of an array parameter by applying sizeof to its name, and you
could get the address of an array parameter by applying unary "&" to its
name.  I know why that doesn't work.  And so do you.

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */