Liste des Groupes | Revenir à cl c |
bart <bc@freeuk.com> writes:Except when it comes to arrays. Obviously arrays aren't passed by value, but that's because of X and Y.
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.
Have a look at forums like the Reddit one on C programming, to see the kinds of things that people learning C get confused about. Lots of them are to do with the funny quirks of C, and a big proportion are due to how arrays and pointers are so intertwined in that language.You're doing your students aIf. Always with the if. There are lots of things I don't do that would
disservice if you try and hide all the quirks.
be doing my students a disservice were I to do them. Beautiful spin!
Les messages affichés proviennent d'usenet.