Re: pointer/ref question
From: Paul (pcr1000011
Date: 02/27/04
- Next message: Paul: "Re: pointer/ref question"
- Previous message: Mike Wahler: "Re: [OT] Visual C++ 6.0"
- In reply to: Leor Zolman: "Re: pointer/ref question"
- Next in thread: Gary: "Re: pointer/ref question"
- Reply: Gary: "Re: pointer/ref question"
- Reply: Leor Zolman: "Re: pointer/ref question"
- Reply: Greg Comeau: "Re: pointer/ref question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 27 Feb 2004 20:00:02 -0000
"Leor Zolman" <leor@bdsoft.com> wrote in message
news:jq8p3091oj9v9clurs5ncqbft8hp0ih9ur@4ax.com...
> On 24 Feb 2004 22:15:02 -0800, wft2vicki@earthlink.net (Vicki) wrote:
>
> >Hi,
> >
> > Can someone help me with the following code? I don't understand why
> >the & (reference...is it called specifier?) is needed with the
> >pointer.
> >
> >function header:
> >
> >void insertAfter(List Cell*& p, int k, int x);
> >
> >I thought that with the pointer, it is already getting passed by
> >reference
>
> You've already gotten good responses that illustrate the basic picture.
> Part of the problem here, IMO, is terminology, and it would seem that
> there's quite a bit of confusion over the meaning of the term "pass by
> reference". Those that have been arguing the point (no pun intended) for
> years seem to have settled on an interpretation of that term that they try
> to disassociate with anything to do with "pointers" in C or C++, but I
> think that is a losing battle in practical terms. I use the term "pass by
> reference" to generically indicate we're conveying the address of an
> object. Thus, to /me/ one can describe both of these situations as
"passing
> x by reference" in C or C++, while the second would only qualify as such
> in C++ (as there's no reference type in C). I'm not adverse to also using
> the term "pass by pointer" for the first case when teaching C++, in order
> to have a separate term for that and passing to a function taking a
> parameter by "real" reference:
>
> void f(int *v) {...};
> void g(int &v) {...};
> int main()
> {
> int x;
> f(&x); // C and C++
> g(x); // C++ only
> }
>
> The key is always use the term "by reference" in context: /What/ are you
> passing by reference? In the call to f, I'm passing x by reference, but
I'm
> passing a pointer to x by value. I'd be doing exactly the same thing if
> I'd created a pointer variable initialized to &x and passed /that/ by
> value.
>
> I've gotten somewhat flamed for using the terms this way in the past, and
> it'll probably happen again in the future (perhaps Real Soon Now), but at
> least my point of view represents a framework where it is possible to
> describe most, if not all, kinds of argument passing in C and C++ with a
> minimal number of ambiguous terms...
> -leor
>
>
Why don't we try to change the phrase 'pass by reference' to something like
'pass by actual' as it can be spurious.
I know I have the habit of saying pass by reference when a pointer is being
used which is probably not technically correct and could be misinterpreted,
a bad habit I think and I will try to start using 'pass by actual' or
something else.
- Next message: Paul: "Re: pointer/ref question"
- Previous message: Mike Wahler: "Re: [OT] Visual C++ 6.0"
- In reply to: Leor Zolman: "Re: pointer/ref question"
- Next in thread: Gary: "Re: pointer/ref question"
- Reply: Gary: "Re: pointer/ref question"
- Reply: Leor Zolman: "Re: pointer/ref question"
- Reply: Greg Comeau: "Re: pointer/ref question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|