Click to See Complete Forum and Search --> : Reference and address of operator


miteshpandey
March 2nd, 2006, 08:12 AM
Why did C++ creators used the same symbol for references and address of operator. When I was a begineer I found it very difficult to differentiate between the two though the right type could be obtained from the context. Is there any advantage in doing so?

ovidiucucu
March 2nd, 2006, 08:33 AM
[ Redirected thread ]
Although later you'll consider that it's not so hard to differentiate from context, this guy is the only one who can give you the best answer:
http://www.research.att.com/~bs/Bjarne.jpg

miteshpandey
March 2nd, 2006, 08:37 AM
Is this Stroustroup himself?

Nice picture :D

ovidiucucu
March 2nd, 2006, 08:42 AM
Yea, it's taken from Bjarne Stroustrup's homepage (http://public.research.att.com/~bs/homepage.html).
You can take a look in it and maybe you can find the answer.

logan
March 2nd, 2006, 08:49 AM
I have put that as my new wallpaper.

I love you Bjarne :-*!

Kheun
March 2nd, 2006, 07:05 PM
I never know there are some people actually worshipping him. :D :D :D

Yves M
March 2nd, 2006, 07:16 PM
It may be confusing, but I don't remember having trouble distinguishing between the two different uses. It's true that something like "void f(int &i)" looks weird when you come from C without references, but then again, the contextual differences are pretty clear though.

exterminator
March 3rd, 2006, 12:31 AM
I never know there are some people actually worshipping him. :D :D :DHe is not worshipping him.. You will find many worshippers though...

He actually is in LOVE with him ... el o vee ee... love.. :D

logan
March 3rd, 2006, 01:57 AM
I love this man too...;)
http://cm.bell-labs.com/cm/cs/who/dmr/dmr.gif

SuperKoko
March 3rd, 2006, 05:35 AM
When I first saw that syntax, I thought it was intuitive, but of course I understand that overuse of the same keywords in different contexts, with different meaning, may be confusing.
For example the "static" keyword has at least three meanings (and a new one in C99).

miteshpandey
March 3rd, 2006, 07:06 AM
I know two meanings of the static keyword.

1. Life time that of the program.
2. Creation of one instance.

Is Internal Linkage the third one?

exterminator
March 3rd, 2006, 07:13 AM
This should be in a new thread...

SuperKoko
March 3rd, 2006, 10:45 AM
static means "instance-independent" when used with members of a class.

It means "internal storage" when used with data/functions at namespace-scope level... what is funny, because with class data members it has external linkage.
It means "static storage duration" for function's static variables.
Since internal storage data implies static storage duration, you can deem that these two last form of "static" have the same semantics (i.e. "internal storage).
But for a beginner, it is not very intuitive that:

static int hello()
{
static int k=42;
return ++k;
}

In that code, the two static words have the same "meaning".
However if the auto keyword was not implicit when declaring variables inside a function, that may seem more intuitive to beginners.

That is why I said that there were three meanings.