Sujet : Re: technology discussion → does the world need a "new" C ?
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.cDate : 15. Aug 2024, 22:52:49
Autres entêtes
Organisation : None to speak of
Message-ID : <877cchfo7i.fsf@nosuchdomain.example.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.13 (Gnus v5.13)
Bart <
bc@freeuk.com> writes:
[...]
However your entry for pointers is not correct: you can pass pointers
by reference (in C, it means passing a T** type instead of T* to
emulate that).
You can *emulate* passing a pointer object by reference in C. You do so
by passing a pointer to the pointer object (or equivalently, the address
of the pointer object). The pointer to the pointer object is of course
passed by value, like all C function arguments.
No doubt you'll complain that I'm being overly pedantic. In fact I'm
pointing out an important distinction that you're glossing over *in a
discussion of that distinction*.
[...]
Pass-by-reference necessarily requires an lvalue at the call-site
since it effectively applies & to the argument.
But a (perhaps hypothetical) non-C language could use pass-by-reference
with a non-lvalue argument. It could do so by creating an implicit
object, initializing it to the argument value, and passing that object
by reference. (I understand that early Fortran did that, leading to the
possibility of CALL FOO(0) changing the value of 0.)
[...]
That's one of the small differences. But you only get the array size
in a language where the array type includes its length. Otherwise, you
only get it if it's part of the parameter type.
A C array type does include its length. int[10] and int[20] are
distinct types. The implicit conversion of an array expression to a
pointer expression loses the length information.
[...]
-- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.comvoid Void(void) { Void(); } /* The recursive call of the void */