DEV Community

Discussion on: Why use pointers at all.

 
jessekphillips profile image
Jesse Phillips • Edited

Let's try it.

"reference values (often just oranges)"

"All interactions with objects and array is by oranges, much like pointers in C."

Yep, I'd use it.

"Objects are pass by oranges and if C had them, it too would be pass by oranges."

Thread Thread
 
pentacular profile image
pentacular

Ok, and does pass-by-orange have pass-by-reference semantics, or does it have pass-by-value semantics? :)

Thread Thread
 
jessekphillips profile image
Jesse Phillips • Edited

Have we defined what we are discussing as passed and the definition of reference yet?

Thread Thread
 
pentacular profile image
pentacular

I've done so several times.

Here is the simplest requirement, again.

When passing by reference, modifying the parameter modifies the argument.

void foo(int &a) {
  a = 2;
}

int main() {
  int i = 1;
  foo(i);
  cout << i << endl;
  // Outputs 2.
}
Enter fullscreen mode Exit fullscreen mode
Thread Thread
 
jessekphillips profile image
Jesse Phillips

Under that definition, no passing by oranges does not have the same semantics as pass by reference.

This however changes the subject to the parameters of the functions. I have been talking about the object for which the parameter refers. Could we stick with talking about the concept I'm actually trying to get across rather than introducing a introducing a different one.

Since pass by oranges is not a term used in the Java spec, could you describe the pass by oranges semantics using spec terms?