Re: couple of general questions
From: Gary Labowitz (glabowitz_at_comcast.net)
Date: 04/06/04
- Next message: Pete: "Re: C++ Homework"
- Previous message: putang1080: "C++ Homework"
- In reply to: Snake: "Re: couple of general questions"
- Next in thread: Snake: "Re: couple of general questions"
- Reply: Snake: "Re: couple of general questions"
- Reply: Snake: "Re: couple of general questions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 5 Apr 2004 21:53:48 -0400
"Snake" <hana1@rogers.com> wrote in message
news:Jxmcc.22056$L_8.19596@news01.bloor.is.net.cable.rogers.com...
<<snip>>
> anyways, I regarding the pointers and
> reference thing.I thought that pointers are under the reference
category
> (and thats how it is in most of the websites) since pointers hold
the
> address of the object and thats what reference is(to you FRANCIS)
Okay, Snake. You DO have a misconception about the nature of
references.
A pointer is a type that contains an address of an object as its
value.
But a reference is not simply a constant pointer. The concept of a
reference is that a reference is an identifier that refers directly to
the same value as the identifier of the caller. In effect, the calling
function is passing the identifier and the called function uses a
different name for it. Example:
Calling function code:
int myName = 17;
passFunction(myName);
Called function code:
void passFunction( type& differentName)
{ differentName = 20; return; }
When the called function uses the identifier "differentName" the
compiled code stores the value 20 directly into the variable that the
calling function uses the identifier "myName" for. They both refer to
the same object using different identifiers. That is all.
There is nothing in this description that forces the compiler to
generate the code using pointers to implement this action, although it
is probably the way all current compilers do it. Notice that the
compiled code, if it uses a pointer mechanism to refer to the value,
does all the dereferencing needed. The writer of the called function
does not have to use a parameter identifier with the * operator.
Now, my contention is that this is the kind of explanation a good book
would have (perhaps with more examples). To explain it here in this
detail and focus is like writing a book on-line. The fact is that many
web sites and books don't explain it this way is sad, but true. ACCU
is your friend, in that case.
I believe that others here have the same point of view with regard to
explaining, in great detail, the basics of the language.
If you (and anyone else) is unhappy with my explanation, then the
comp.lang.c++ newsgroup is probably the correct place to discuss this.
Have a good day.
-- Gary
- Next message: Pete: "Re: C++ Homework"
- Previous message: putang1080: "C++ Homework"
- In reply to: Snake: "Re: couple of general questions"
- Next in thread: Snake: "Re: couple of general questions"
- Reply: Snake: "Re: couple of general questions"
- Reply: Snake: "Re: couple of general questions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|