Sujet : Re: technology discussion → does the world need a "new" C ?
De : tr.17687 (at) *nospam* z991.linuxsc.com (Tim Rentsch)
Groupes : comp.lang.cDate : 15. Aug 2024, 09:43:38
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <86a5hep45h.fsf@linuxsc.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
User-Agent : Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Bart <
bc@freeuk.com> writes:
[on comparing array arguments in C with call-by-reference]
[...] the differences [between C rules and true call-by-reference]
can be summarised here; [...]
>
Call Array access in callee
>
C call-by-value F(A) A[i]
>
true call-by-reference H(A) A[i]
>
What the user has to write is what's important, and here it is clear
that they write the same thing [in the two cases shown].
The comparison above is misleading because it is incomplete.
Let's compare the two modes more fully:
C call-by-value call-by-reference
=============== =================
at call:
(array argument) F(A) H(A)
(pointer argument) F(p) (disallowed)
(null argument) F(0) (disallowed)
inside function:
(access) A[i] A[i]
(update) A[i] = ... A[i] = ...
sizeof A (pointer size) (array size)
A++ (changes A variable) (disallowed)
A = (new value) (changes A variable) (disallowed)
The more complete comparion illustrate why C semantics should not
be thought of as call-by-reference.