The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: pavellus on August 22, 2006, 01:20:30 PM

Title: pointers and references
Post by: pavellus on August 22, 2006, 01:20:30 PM
What is different between pointers and references?
Pointer are addresses to values but i can't see what for use references?
Title: Re: pointers and references
Post by: Tedd on August 22, 2006, 01:49:11 PM
There isn't any difference in asm :bdg
It's higher-level langauge (C++, etc) decoration really - a pointer is an address, a reference is a pointer that gets 'dereferenced' automatically (when you use it, you the get the thing it points to, not the pointer itself.)
Title: Re: pointers and references
Post by: pavellus on August 22, 2006, 01:56:43 PM
Maybe reference is a pointer to pointer or i am wrong?
Title: Re: pointers and references
Post by: Tedd on August 22, 2006, 02:02:20 PM
No, it's just a pointer.
But for higher-level languages (NOT asm) it's a 'magic' pointer where you get the thing it points to, not the actual pointer itself.
Title: Re: pointers and references
Post by: Boucly on August 22, 2006, 02:05:36 PM
pavellus

Did you Google (http://www.google.co.uk/search?hl=en&q=C%2B%2B+tutorial+reference&meta=) it?
This is what I found - About - C++ Tutorial - Lesson 13: References (http://cplus.about.com/od/beginnerctutorial/l/aa061002a.htm)

I don't think it is going to help you much though. It is basically what Tedd had already told you.

Here's a quote from the page, if it makes sense to you (it doesn't mean anything me, I don't really know what it's saying! Too technical.)

QuoteA reference is not a unique object. It is merely an alias or synonym for another object. The reference identifier (name) may be used anywhere the referred identifier may be used. Any changes to the reference also apply to the original object. Changes to the original object are also seen through the reference.

Boucly
Title: Re: pointers and references
Post by: Tedd on August 22, 2006, 06:21:32 PM
Okay, maybe an example will make it clearer.

a = 5
b = pointer_to_a
c = reference_to_a

d = b    // gives the address of a - it's a pointer
d = c    // gives 5 (the value of 'a') - it's a magic pointer

Title: Re: pointers and references
Post by: Boucly on August 22, 2006, 06:25:36 PM
So that's why you said it is not an assembly thing!  :U
Thanks! Funny though, I learned C++ for quite a long time but never came across references.

Boucly
Title: Re: pointers and references
Post by: zooba on August 25, 2006, 12:00:42 AM
Quote from: Boucly on August 22, 2006, 06:25:36 PM
I learned C++ for quite a long time but never came across references.

I'm pretty sure references only came in the most recent revision (1999, IIRC).