6

I always thought call-by-value and pass-by-value were synonymous. However, I recently heard someone refer to them as if they were different. Are they the same thing?

I'm also talking about their corresponding by-reference terms too.

royco
  • 5,409
  • 13
  • 60
  • 84

5 Answers5

6

"Someone," is wrong. Check out the Wikipedia article which directly answers your question. You can point that certain "someone" at this article, as well:

Call-by-value evaluation (also referred to as pass-by-value) is the most common evaluation strategy, ...

Michael Goldshteyn
  • 71,784
  • 24
  • 131
  • 181
5

They are synomynous.

"call" means the method, and "pass" means an(the) argument(s).

Example:

  1. argument #1 was passed by value/reference.
  2. the arguments were passed by value.
  3. the method is used in a call by value context.
Femaref
  • 60,705
  • 7
  • 138
  • 176
  • Pointing out that "call" refers to the method and "pass" refers to the argument makes it all makes sense. Thanks. – royco Feb 13 '11 at 22:29
1

Yes those terms are synonyms as I understand them.

However, I think you are asking the wrong audience. If your colleague regards them as different, then you and they have a mismatch of understanding. Whether or not I think they are the same is irrelevant, what counts is what your colleague actually means.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
1

They are synonymous. The term call-by-value means exactly the same as pass-by-value.

However, I prefer the pass-by-value form, as it's the parameter that is passed that it refers to. A call can have parameters that are passed by value as well as parameters passed by reference.

Example:

public void Something(string name, int count, ref string target, ref int result)

The first parameter is a reference passed by value, the second is a value passed by value, the third is a reference passed by reference, and the fourth is a value passed by reference.

Guffa
  • 687,336
  • 108
  • 737
  • 1,005
1

I've always considered them synonymous, but when I think about it, perhaps they're trying to differentiate between calling a method directly and calling a method through a reference (i.e. a delegate). That is, given this:

public delegate void MyDelegate();

class MyClass
{
    public void DoSomething()
    {
        // ...
    }
}

MyClass thing = new MyClass();

Are they trying to say that if you write:

thing.DoSomething();

Then it's a "call by value", but if you write:

MyDelegate dlgt = thing.DoSomething;
dlgt();  // calls thing.DoSomething through the delegate reference

then it's a "call by reference?"

Jim Mischel
  • 131,090
  • 20
  • 188
  • 351