Liste des Groupes | Revenir à cl c |
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:>
>
void F(int a[20]) {}
>
int main(void) {
int x[20];
F(x);
}
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. You're doing your students a
disservice if you try and hide all the quirks.
Les messages affichés proviennent d'usenet.