Are call-by-value and pass-by-value synonymous?
Asked Answered
F

5

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.

Fant answered 13/2, 2011 at 22:12 Comment(0)
D
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.
Disparagement answered 13/2, 2011 at 22:15 Comment(1)
Pointing out that "call" refers to the method and "pass" refers to the argument makes it all makes sense. Thanks.Fant
S
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, ...

Syriac answered 13/2, 2011 at 22:18 Comment(0)
D
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.
Disparagement answered 13/2, 2011 at 22:15 Comment(1)
Pointing out that "call" refers to the method and "pass" refers to the argument makes it all makes sense. Thanks.Fant
D
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.

Denominationalism answered 13/2, 2011 at 22:14 Comment(1)
True, but I don't know how to reach the fellow. Thanks for the response!Fant
C
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.

Chapple answered 13/2, 2011 at 22:20 Comment(0)
J
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?"

Jorum answered 13/2, 2011 at 22:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.