3 ms·
You're ignoring my point, which is that you need the distinction between call-by-value and call-by-reference to explain what happens if you assign to a paramete
by fauigerzigerk 9y ago
You're ignoring my point, which is that you need the distinction between call-by-value and call-by-reference to explain what happens if you assign to a parameter.
I think it's obvious that I was talking about assigning to pointer variables because parameters are always variables and never just values.
- lisper 9y agoI'm not ignoring your point. I'm saying that your point is not a point worth making, at least not in the context of talking about relevant distinctions among different programming languages. > you need the distinction between call-by-value and call-by-reference to explain what happens if you assign to a parameter You only need this distinction if: 1) Different programming languages actually handle this differently and 2) You actually assign to function parameters If either of these conditions do not hold then you don't need the distinction. And in fact: 1) All programming languages in use today are call-by-value by default. A very small subset of them offer call-by-reference as an option. And... 2) Assigning to function parameters is never a good idea. If you're assigning to a function parameter you are almost certainly doing something wrong.
- fauigerzigerk 9y ago>If either of these conditions do not hold then you don't need the distinction. Agreed, but both conditions do hold. C++, C# and Swift support both call-by-value and call-by-reference. And the feature is actually used as most of these languages don't have (or didn't originally have) tuples or multi-valued return. Whether or not it's a good idea to assign to reference parameters is a wholly different matter. But even bad ideas need language to explain them.
- UncleMeat 9y agoBut cpp doesn't have call-by-reference. It has the ability to refer to pointer and reference objects directly and pass those by value. foo(int* x) takes a pointer by value. foo(int& x) takes a reference by value.
- fauigerzigerk 9y agoThat's nitpicking. Pass-by-reference is defined by its semantics, not by an implementation that avoids copying anything. There is no such thing as a "reference object" in C++ that you could pass by value. References may be implemented using pointers under the hood and those pointers may be copied, but on a semantic level references themselves are not objects that you can copy or take the address of (contrary to pointers).