Liste des Groupes | Revenir à cl c |
bart <bc@freeuk.com> writes:Though, in ABI specs, this would usually still be termed as "pass by reference" rather than "pass by pointer" or "pass by address" (and neither has any relation to "reference" as it might be used in a language like C++, or IOW passing the address of the pointer holding the address of the array... which I don't think anyone was arguing for here; or how it is used in Visual Basic, where it means that function arguments assigned in the callee are visible to the caller, which is also different, ...).
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.
Sorry, I missed what you wrote. I don't know why even brought up intvoid F(int a[20]) ... declares a to be of type int *. Feel free to rail>
about that as much as you like but that is what that syntax means.
The x in F(x) is converted to a pointer to x[0] since the x is not an
operand of &, sizeof etc. F(x) passes a pointer by value. F receives a
pointer value in a.
>Although the type of 'a' inside 'F' will be int* rather thanNo. a is of type int *.
int(*)[20].
And that is different 'int*' how, about from having an extra space which C
says is not signigicant in this context?
(*)[20] but I thought you were saying that was the type of a.
Les messages affichés proviennent d'usenet.