Re: pass by reference



"Roedy Green" <see_website@xxxxxxxxxxxxxxxxxxxx> wrote in message
news:fhqfv3tl9v507ngchf95shmuv3i11c7gik@xxxxxxxxxx
On Sat, 05 Apr 2008 12:01:49 GMT, "Arved Sandstrom"
<asandstrom@xxxxxxxxxxxxx> wrote, quoted or indirectly quoted someone
who said :

I may get flunked on a certification exam, but I call that
passing the object by reference.

Language is for communication. If you use a word to mean something
different from everyone else does, you just create chaos when you
speak.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

However, I don't think I mean "pass by reference" and "pass by value" as
anything other than the intuitive meanings:

a) pass by value - the method sees a copy of the parameter, whatever that
may be;

b) pass by reference - the method sees an alias to the parameter. If the
method uses the parameter it is using the actual thing referred to.

With objects Java does (b). I don't care if you call it "passing the
reference by value", or "passing a pointer", or whatever. If I do

Some Object so = new SomeObject(...);
makeChangesToFields(so);

then the fields in 'so' are changed outside the method. This is
pass-by-reference behaviour, not pass-by-value behaviour.

For the record I don't like the "swap" example that gets trotted out to
explain that Java is not pass-by-reference (as an example,
http://www.javaworld.com/javaworld/javaqa/2000-05/03-qa-0526-pass.html).
It's disingenuous. If I write the same example using C++ with pointers to
objects, I get the same results...surprise, surprise.

AHS


.



Relevant Pages

  • Re: pass by reference
    ... There really isn't a widely used definition of a reference. ... C++ means one thing; Java ... "pass pointer by value". ... grasps the difference between passing a pointer by value and passing ...
    (comp.lang.java.programmer)
  • Re: pointer/ref question
    ... reference" to generically indicate we're conveying the address of an ... to /me/ one can describe both of these situations as "passing ... the term "pass by pointer" for the first case when teaching C++, ...
    (alt.comp.lang.learn.c-cpp)
  • Re: How to pass a reference to a CComBSTR
    ... >> This is not passing by reference - you are passing pointers. ... CComBSTR tempCComBSTR); ... Approach B (passing by pointer) ...
    (microsoft.public.vc.atl)
  • Re: using const & in function prototypes
    ... BOOL func; ... You are passing a reference to an object instead of a copy. ... passing a pointer is at best as performant as passing a DWORD, ...
    (microsoft.public.vc.language)
  • Re: no pointer in Java => my problem
    ... > There are no value objects in java. ... Z is a reference passed by value. ... > References are similar to C pointers, ... you are passing is an adress and you can't change the address. ...
    (comp.lang.java.programmer)