Re: pointer/ref question

From: Paul (pcr1000011)
Date: 02/27/04


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.



Relevant Pages

  • Re: pointer/ref question
    ... reference" to generically indicate we're conveying the address of an ... to /me/ one can describe both of these situations as "passing ... the term "pass by pointer" for the first case when teaching C++, ...
    (alt.comp.lang.learn.c-cpp)
  • Re: How to pass a reference to a CComBSTR
    ... >> This is not passing by reference - you are passing pointers. ... CComBSTR tempCComBSTR); ... Approach B (passing by pointer) ...
    (microsoft.public.vc.atl)
  • Re: using const & in function prototypes
    ... BOOL func; ... You are passing a reference to an object instead of a copy. ... passing a pointer is at best as performant as passing a DWORD, ...
    (microsoft.public.vc.language)
  • Re: no pointer in Java => my problem
    ... > the value you are passing is an adress and you can't change the ... When passing a reference, you don't get ... access to the pointer. ... Neither Java nor C have anything resembling this. ...
    (comp.lang.java.programmer)
  • Re: [PATCH] [0/9] Use 64bit x86 machine check code for 32bit too
    ... warning: passing argument 2 of ‘strict_strtoull’ makes integer from pointer without a cast ...
    (Linux-Kernel)