3 ms·
The difference between pass-as-reference and pass-by-reference is more than trivia - if you were ignorant of it in a language, you might find trouble in the fut
by ivanbakel 9y ago
The difference between pass-as-reference and pass-by-reference is more than trivia - if you were ignorant of it in a language, you might find trouble in the future when a function decides to alter its argument values in a way that negatively affects the caller. Part of the reason we should work to clarify the language is to avoid misconceptions about behaviour based on what kind of "reference" is meant.
- tetromino_ 9y agoA language with pointers also allows a function to alter its logical (not syntactical) argument values in a way that negatively affects the caller. There isn't much practical difference between using // void c_func_alters_deref_pfoo(Foo * pfoo) Foo foo = { ... }; c_func_alters_deref_pfoo(&foo); and // void cpp_func_alters_foo(Foo & foo) Foo foo = { ... }; cpp_func_alters_foo(foo); besides the ability to pass null or otherwise invalid pointers in the C-style version, which can (depending on situation) either simplify your API or be a source of bugs.
- ivanbakel 9y ago>A language with pointers also allows a function to alter its logical (not syntactical) argument values What's the difference between a logical and syntactical argument?