Re: Pointer vs Reference



On 2007-09-30 07:16, Roedy Green wrote:
On Sat, 29 Sep 2007 22:56:52 GMT, Erik Wikström
<Erik-wikstrom@xxxxxxxxx> wrote, quoted or indirectly quoted someone
who said :

Foo f1 = new Foo();
Foo f2 = f1;

While it does not exactly take the address of the object referred to by
f1, it does create a new reference (pointer) that points to the same object.

In assembler, what that does in allocate space for a new Foo object on
the heap somewhere. It puts the 32-bit address of that object in f1, a
local variable allocated on the stack frame.

Then it copies the pointer value from f1 and stores it in f2.

No reference is created, except on the initial allocation.

Removing comp.lang.c++ form the discussion since it is becoming Java only.

Oh, I see, I was under the impression that f1 was a reference. Just out
of curiosity what is a reference in Java? Does f1 (and later f2) point
to a reference which refers to the Foo object, or is the Foo object the
reference (which would be quite counter intuitive)?

--
Erik Wikström
.



Relevant Pages

  • Re: C++ design question
    ... >>void DoStuffWithBarBase ... I assumed that the Foo subclasses each had specialized responsibilities, ... policies for object and relationship instantiation (object ... conditional one can't implement it with a reference. ...
    (comp.object)
  • Re: pass by Reference/value ???
    ... > void foo ... this would be called "passing by reference". ... foo receives a local copy of s and any changes that it makes to s only ... Since s is a pointer, a variable storing the address of s is a pointer to ...
    (comp.lang.cpp)
  • Re: How to undo a bless on a GLOB
    ... The reference was blessed to something: ... bless $foo, 'Something'; ... Can you bless the glob before ... That could be a bug in POE. ...
    (comp.lang.perl.misc)
  • Re: Objects that cant be garbage collected?
    ... and that it is collected before an instance of Foo calls a ... if the reference in Foo to ... A class loader may be reclaimed, along with any class that is within it, following the same logic as any other object. ... Daniel Pitts' Tech Blog: ...
    (comp.lang.java.programmer)
  • Re: Inheritance of constructors.
    ... Bare in mind that was just for sake of example. ... In case of "reference by value" that's not ... Foo foo = new Foo; ... The changes to the array are visible in Foo, ...
    (microsoft.public.dotnet.languages.csharp)