Re: better understanding references
From: jeffc (nobody_at_nowhere.com)
Date: 03/04/04
- Next message: Leor Zolman: "Re: better understanding references"
- Previous message: David White: "Re: [OT] Re: better understanding references"
- In reply to: thides: "Re: better understanding references"
- Next in thread: jeffc: "Re: better understanding references"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 4 Mar 2004 17:54:24 -0500
"thides" <swatts@globalserve.net> wrote in message
news:yCN1c.69745$bJ6.19904@nntp-post.primus.ca...
>
> "jeffc" <nobody@nowhere.com> wrote in message
> news:40475820_3@news1.prserv.net...
> >
> > "thides" <swatts@globalserve.net> wrote in message
> > news:bWy1c.68187$lx2.42640@nntp-post.primus.ca...
> > >
> > > When is & (address of ) not used to take an address?
> >
> > When you're using it in the callee to mean "pass by reference" :-)
>
> Yes but in the sort example my understanding is 'sort(int &i, int &j)'
> accepts the address of what it is passed as oppose to the value. Its not
> that we are dealing with the value but the address of the value of what is
> passed. And as was pointed out in the FAQ or in one of the responses to
the
> original question the compiler does the dereferencing automatically so we
> dont have to mess around with pointers. & is always related to addresses
of
> some type or meaning except used with binary or logical operators.
Right?
Well, probably, but that is not the way you're supposed to think. When you
push your gas pedal, you want your engine to speed up. You don't care if
that happens with a carburetor or fuel injection. Likewise, in the function
declaration you showed, there is no reason to think of addresses at all, and
I'm sure the designer of the feature did not want you to think in those
terms either. You should think only in terms of "pass by reference".
Whether this happens with taking the address or not is none of our concern.
Let's say someone wants to call sort. Should the programmer think about how
to get the addresses of his variables in there? Definitely not. He should
just call it like this:
int x;
int y;
scan(x, y);
That's it. "pass by reference", not "pass by value". "Address" never
needs to be considered.
- Next message: Leor Zolman: "Re: better understanding references"
- Previous message: David White: "Re: [OT] Re: better understanding references"
- In reply to: thides: "Re: better understanding references"
- Next in thread: jeffc: "Re: better understanding references"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|