Liste des Groupes | Revenir à cl c |
On 10/07/2024 14:32, Ben Bacarisse wrote:bart <bc@freeuk.com> writes:>
On 10/07/2024 00:35, Ben Bacarisse wrote:The oddity is that, in C, one can't pass arrays to functions at all.bart <bc@freeuk.com> writes:>
>On 09/07/2024 18:22, Ben Bacarisse wrote:Parameter passing is relatively simple though since there is only onebart <bc@freeuk.com> writes:>
>On 09/07/2024 16:58, Ben Bacarisse wrote:An address value is passed by value. C has only one parameter passingbart <bc@freeuk.com> writes:>
>Arrays are passed by reference:This is the sort of thing that bad tutors say to students so that they
>
void F(int a[20]) {}
>
int main(void) {
int x[20];
F(x);
}
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.
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.
mechanism -- pass by value.
Except when it comes to arrays.
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?!"
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.
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!
Les messages affichés proviennent d'usenet.