Talk:Language Comparison Table: Difference between revisions

Line 94:
 
One instructive resource is the [[Generic swap]] task. The languages that can perform a swap of two argument variables, without any special caller intervention, like taking the address or putting them in an auxiliary data structure, and affect the caller's variables (instead of just returning the new values), and not doing something like switching the object contents to look like the references to them have been swapped when they really haven't; such languages I would consider pass-by-reference. --[[User:Spoon!|Spoon!]] 20:15, 1 February 2009 (UTC)
 
: I agree with the fact that the "feature" that makes the difference between the two ways of passing arguments to a function is if the callee is able to modify the "original" thing "owned" by the caller (if I've understood well what you've written) or not. Nonetheless there are proper definitions in literature; as far as I know, these say that "passing by reference" allows the modification of the caller copy, while "passing by value" allows it not, since what you have in the callee is just a (local) copy of the original.
 
: How exactly these ways are implemented are different; in C, to allow the modification of a caller "object", one must pass the pointer to it (the pointer itself is passed by value...); dereferencing the pointer one can modify the local copy of the caller. But other languages may use different terminology and what's going on is hidden by abstraction. As far as I know, in C++ (or was it another lang I am confonding C++ with?:D) the "references" are none but aliases for the same object; so told, I would say the pass-by-reference can be implemented at compile time creating a symbol in the compiler symbol table that is linked to the same "content" of another symbol (roughly speaking).
 
: Anyway, C has no language syntax for referencing like C++; it is less abstract, more "low level", and the only thing one can do is to pass pointers; if the "number" N points to memory "cell" N containing e.g. an int, "dereferencing" the pointer from inside a func or another one "reads" the same memory "cell", i.e. the same int... and so it is for writing. All the arguments passed to a function are a (local) copy, and maybe we can say all are passed-by-value.
 
: In C, there's the convention of considering a pointer like a reference. More abstract languages can call "reference" something different (the underlying implementation likely uses pointers, but this is hidden as said; in C, it can't be hidden: it must be done explicity, and it is why I consider C like it has no pass-by-reference, but only a pass-a-pointer, that is a type as int, float or another, except that we can "take" what the pointer is pointing to, which is the most common operation we do on pointers, altogether with incrementing and decrementing it ---and C does not check bounds:D)
 
: There's another difference (between C and C++): in C, "pass-by-reference" needs awareness by the caller, which must obtain the pointer of the object it wants the callee can modify. In C++, pass-by-reference does not need the "help" of the caller, it is a request of the callee, by declaration. --[[User:ShinTakezou|ShinTakezou]] 23:03, 1 February 2009 (UTC)