Liste des Groupes | Revenir à cl c |
On 15/08/2024 18:08, Bart wrote:So, you agree that it is similar to. And not just the resulting syntax, but the semantics and even the generated code can be the same (as I demonstrated but somebody complained).
These were my original comments on the subject made to DB:I am not sure if you want an answer here or not - you asked "so what then", but also asked to avoid a re-run of the thread.
>
>
DB:
>. In C, there is no "pass by reference" or "return by reference". It is all done by value.
>
BC:
>
>Arrays are passed by reference:
>
> void F(int a[20]) {}
>
> int main(void) {
> int x[20];
> F(x);
> }
>
> Although the type of 'a' inside 'F' will be int* rather than int(*)[20].
>
It was in reply to DB which appear to imply that arrays were passed by value. Obviously they're not passed by value, so what then? (Please, don't rerun the thread! This is where everyone jumped in.)
>
I can give a summary - and I also hope this doesn't lead to a re-run of the discussion. However, since you are asking the same question as you did at the start, and the language C has not changed in the meantime, the factual and correct answers will inevitably be the same:
1. C has no "pass by reference" - it is all "pass by value".
2. In C, you cannot pass an array as a function parameter.
3. The automatic conversion of many array expressions to pointer expressions, along with the similar conversions of function parameter types, gives C users a syntax that is similar - but not identical to - what you would have if the language supported passing arrays by reference.
4. Adding "pass by reference" and "arrays as first class objects" would both be very significant changes to CAdding pass-by-reference would not be a huge change. I added that using a cheap and cheerful approach that seems work well enough (a parameter marked as by-ref, would have '&' automatically applied on arguments, and '*' automatically applied to parameter accesses in the callee**).
Les messages affichés proviennent d'usenet.