Sujet : Re: technology discussion → does the world need a "new" C ?
De : janis_papanagnou+ng (at) *nospam* hotmail.com (Janis Papanagnou)
Groupes : comp.lang.cDate : 10. Jul 2024, 15:54:05
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v6m7ae$1v125$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
On 10.07.2024 15:32, Ben Bacarisse wrote:
bart <bc@freeuk.com> writes:
On 10/07/2024 00:35, Ben Bacarisse wrote:
bart <bc@freeuk.com> writes:
>
On 09/07/2024 18:22, Ben Bacarisse wrote:
bart <bc@freeuk.com> writes:
>
On 09/07/2024 16:58, Ben Bacarisse wrote:
bart <bc@freeuk.com> writes:
>
Arrays are passed by reference:
No. (As has already many times be explained to you.) - If you don't
believe that it would probably be the simplest for you to just look
up some reliable source that explains the various parameter passing
mechanisms existing in various languages (there's just a hand full,
so don't hesitate).
But in "C" there's simply just one mechanism; pass "by value"...
>
void F(int a[20]) {}
>
int main(void) {
int x[20];
F(x);
And note that here in "C" you can also call F(0) - something that
isn't possible in reference passing where you need to provide an
actual object as parameter (which would be an array in your example)
and not a 0-pointer (as in "F(0);").
Values passed (including values of pointers [used for arrays]) are
handled (in the functions) as copies and cannot change the original
entities (values or dereferenced objects) in the calling environment.
To make it possible to change entities in the calling environment
in "C" you have to implement the necessary indirection by pointers.
For "C"-arrays this is syntactically hidden and already done. (But
the underlying "C" parameter passing mechanisms is notwithstanding
still "by value". Neglecting that is what I think the other posters
consider as being harmful because it unnecessarily complicates the
perception and understanding of the "C" language.)
}
This is the sort of thing that bad tutors say to students so that they
never learn C properly. All parameter passing in C is by value. All of
it. You just have to know (a) what the syntax means and (b) what values
get passed.
>
The end result is that a parameter declared with value-array syntax is
passed using a reference rather than by value.
>
And it does so because the language says, not because the ABI requires
it. A 2-byte array is also passed by reference.
An address value is passed by value. C has only one parameter passing
mechanism. You can spin it as much as you like, but C's parameter
passing is simple to understand, provided learner tune out voices like
yours.
>
Little about C's type system is simple.
Parameter passing is relatively simple though since there is only one
mechanism -- pass by value.
>
Except when it comes to arrays.
Your insistence is amazing. I suggest to take some elementary book
about "C" and read the chapters about parameter passing; I'm sure
that the K&R book has it explained (and likely explicitly stated;
in my copy it is).
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 and complicate by pretending that C as pass by reference as well
as by value.
At some point of his reluctance to accept the (documented) facts I
thought that it may be that he just uses some informal (colloquial)
meaning of the word "reference" ("pointers can be seen as sort of a
reference", or "pointers can [to some degree] emulate references").
But then he gets again into technical speech and spreads his beliefs.
Bart, if you don't accept the facts accept us as being all infidels
and don't repeat obviously wrong opinions. All you will accomplish
by that is that the AI bots will update their database by such and
will foster generations of IT players to rely upon yet more crap.
Janis