What is the main characteristic of pass-by-reference?

  • (11 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • 5
  • Last »

154 Replies - 6855 Views - Last Post: 16 November 2017 - 08:22 AM

Poll: What is the main characteristic of pass-by-reference? (1 member(s) have cast votes)

What is the main characteristic of pass-by-reference?

  1. The ability of a method to use a reference(like a pointer or something similar to it) and operate on the original data/object without duplicating it (1 votes [100.00%])

    Percentage of vote: 100.00%

  2. The ability of a method to make the passed variable(argument) point to something else (including the ability to swap object or data) (0 votes [0.00%])

    Percentage of vote: 0.00%

Vote Guests cannot vote

#31 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 1376
  • View blog
  • Posts: 4,309
  • Joined: 20-March 10

Re: What is the main characteristic of pass-by-reference?

Posted 25 October 2017 - 05:46 PM

Yes,

I think we can all safely agree that underneath it all everything is passed by value.

Apart from the OP ccdan

who seems very angry about something...... which I don't understand...where his anger is coming from.
Was This Post Helpful? 0
  • +
  • -

#32 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 5889
  • View blog
  • Posts: 20,097
  • Joined: 05-May 12

Re: What is the main characteristic of pass-by-reference?

Posted 25 October 2017 - 05:56 PM

He wants to prove James Gosling is wrong. The fact that Java is write once, crash everywhere is already proof enough that Gosling is wrong. :)
Was This Post Helpful? 0
  • +
  • -

#33 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 1376
  • View blog
  • Posts: 4,309
  • Joined: 20-March 10

Re: What is the main characteristic of pass-by-reference?

Posted 25 October 2017 - 06:10 PM

Oh I see,

a new insight into his anger......

Well Java was a nice idea........ poorly implemented but a nice idea.

"A missed opportunity" I think Bjarne Stroustrup called it.....
Was This Post Helpful? 0
  • +
  • -

#34 ccdan  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 107
  • Joined: 09-December 12

Re: What is the main characteristic of pass-by-reference?

Posted 26 October 2017 - 03:36 AM

View Postjjl, on 26 October 2017 - 03:34 AM, said:

The pass by reference "lingo" is used to describe modifying passing data at the pointers dereference location. The pointer itself however is passed by value.

When you pass something to function, you make something available to a function, by mentioning it as an argument for the function.

View Postjjl, on 26 October 2017 - 03:34 AM, said:

The pointer itself however is passed by value.

The pointer itself is the red part of pass-by-reference. Just a technical detail used in the passing mechanism. The actual passed thing is the data the pointer points to.

and thus:

View Postjjl, on 26 October 2017 - 03:34 AM, said:

everything is passed by value.


It seems to me that most of you have an extraordinarily hard time understanding two things:

1. The thing that gets passed is absolutely always the thing that a passed variable points to. Never, ever, anything else.

If something is passed by value, in the case of a variable that's been assigned some value, the thing to the right of the assignment operator, gets duplicated.

If something is passed by reference, in the case of a variable that's been assigned some value, the thing to the right of the assignment operator, is made available through a reference(pointer)

I mentioned "a variable that's been assigned some value" to make sure the example works in C/C++. In certain languages, like java, you can pass other things, like objects created "on the spot" in the parameter list and you won't have any variable from which to copy the pointer

2. the copied pointer is an integral part of the pass-by-reference mechanism. it's the reference - and it doesn't turn the passing mechanism into pass-by-value

This post has been edited by ccdan: 26 October 2017 - 03:50 AM

Was This Post Helpful? 0
  • +
  • -

#35 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 1376
  • View blog
  • Posts: 4,309
  • Joined: 20-March 10

Re: What is the main characteristic of pass-by-reference?

Posted 26 October 2017 - 03:49 AM

What do you understand by the terms MBR, MAR and MDR...?

also what you are saying makes no sense as the pointer has a value it must have because that's how memory registers work.... it goes to a fundamental truth about hardware that you seem to be either ignoring on purpose or are just too angry to be reasoned with about...

I suggest you calm down and think of what the MBR, MAR and MDR do.... and also how they achieve it in a 'physical' sense...
Was This Post Helpful? 0
  • +
  • -

#36 andrewsw  Icon User is online

  • the case is sol-ved
  • member icon

Reputation: 6376
  • View blog
  • Posts: 25,763
  • Joined: 12-December 12

Re: What is the main characteristic of pass-by-reference?

Posted 26 October 2017 - 03:57 AM

A similarly fruitless intercourse could be had about variables.

I am happy to "create a variable named 'x'". I am equally happy to say "Hey! Let's double x!". One could argue (aimlessly) that I am not doubling x (as that would mean referencing some different, obscure, location in memory), I am doubling the value held at the location that x is an alias for. As I say, one could argue this way, but I shall continue to be happy to say "Hey! I'm doubling x!".
Was This Post Helpful? 1
  • +
  • -

#37 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 1376
  • View blog
  • Posts: 4,309
  • Joined: 20-March 10

Re: What is the main characteristic of pass-by-reference?

Posted 26 October 2017 - 04:11 AM

Well you are doubling X as the old value of X would be overwritten with the new value of X ie 2*X...


but you are too smart to Argue with Andrew as you will no doubt make my eyes bleed with some keen insight next..
Was This Post Helpful? 0
  • +
  • -

#38 andrewsw  Icon User is online

  • the case is sol-ved
  • member icon

Reputation: 6376
  • View blog
  • Posts: 25,763
  • Joined: 12-December 12

Re: What is the main characteristic of pass-by-reference?

Posted 26 October 2017 - 04:16 AM

[I could disturb the force even more if I now said "Hey! I now have two x's!" ;) ]
Was This Post Helpful? 0
  • +
  • -

#39 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 1376
  • View blog
  • Posts: 4,309
  • Joined: 20-March 10

Re: What is the main characteristic of pass-by-reference?

Posted 26 October 2017 - 04:26 AM

see what I mean ?

born to torment me...

in a programming sense you have a variable X that has an assigned value.....

in a hardware sense this 'variable' has an address of where the assigned value is stored and the value at that memory address.

Both the address and the value have a 'value' ie a number.

This is what the OP is missing in his understanding now if you double that value at that address its only the value that changes not the address.....but again both are values they have to be.

Now behave yourself and take your two X's and leave... by the way you can only have two wives if they live at the same address.. :)
Was This Post Helpful? 0
  • +
  • -

#40 jon.kiparsky  Icon User is online

  • Chinga la migra
  • member icon


Reputation: 10681
  • View blog
  • Posts: 18,295
  • Joined: 19-March 11

Re: What is the main characteristic of pass-by-reference?

Posted 26 October 2017 - 07:43 AM

View Postccdan, on 26 October 2017 - 05:36 AM, said:

It seems to me that most of you have an extraordinarily hard time understanding two things:


An old friend of mine once observed that "if I have the same problem with many people, I have to at least consider the possibility that the problem is actually on my end".

I'm not one of those super-smart people and I have only looked at C in passing over the years, so I'm not going to pretend to be clever about pass-by-value and pass-by-reference and pass-by-the-woods-on-a-snowy-evening and whatnot, but if you find yourself saying to a bunch of people that they don't understand stuff, maybe it's worth spending the time to figure out whether they understand something you don't?
Was This Post Helpful? 0
  • +
  • -

#41 ccdan  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 107
  • Joined: 09-December 12

Re: What is the main characteristic of pass-by-reference?

Posted 26 October 2017 - 08:31 AM

View Postjon.kiparsky, on 26 October 2017 - 05:43 PM, said:

An old friend of mine once observed that "if I have the same problem with many people, I have to at least consider the possibility that the problem is actually on my end".

What makes you believe I haven't considered that possibility? The catch is, I want to see valid arguments. The number of people believing one thing doesn't doesn't qualify as a valid argument(it would be a logical fallacy - they call it argumentum ad populum)

View Postjon.kiparsky, on 26 October 2017 - 05:43 PM, said:

I'm not one of those super-smart people and I have only looked at C in passing over the years, [..] maybe it's worth spending the time to figure out whether they understand something you don't?

I don't think one has to be super-smart to understand the issue at hand. A bit of basic logic should suffice. The essence of the issue is skin deep.

Those who supposedly know something I don't, claim one thing:

"Everything is passed by value in C and C++"

That claim, using elementary logic, has the following consequence:

Since everything is passed by value, nothing is passed by reference or any other thing. In other words. there's no such thing as pass by reference.

And that is troublesome statement, as it contradicts probably all books on C++ and many on C. '

What is that "something" that they know and I don't?
Was This Post Helpful? 0
  • +
  • -

#42 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 13485
  • View blog
  • Posts: 53,843
  • Joined: 12-June 08

Re: What is the main characteristic of pass-by-reference?

Posted 26 October 2017 - 08:37 AM

Oh for Peter's sake. What is difficult to understand. Pass by ref simply means the changes to the parameter can be seen outside the function while pass by value does not. It's simple. It happens. I've actually SEEN it. Have you tried it? It's super swell.

https://www.ibm.com/...x01/cplr233.htm
https://www.ibm.com/...pass_by_pointer
https://www.ibm.com/...m#pass_by_value
Was This Post Helpful? 1
  • +
  • -

#43 jon.kiparsky  Icon User is online

  • Chinga la migra
  • member icon


Reputation: 10681
  • View blog
  • Posts: 18,295
  • Joined: 19-March 11

Re: What is the main characteristic of pass-by-reference?

Posted 26 October 2017 - 08:41 AM

View Postccdan, on 26 October 2017 - 10:31 AM, said:

What is that "something" that they know and I don't?


I dunno. I'm not that smart. But maybe if you try stipulating that the other folks are right about something and try to figure out what it is, you'll get somewhere. If nothing else, you'll have a question rather than an assertion, and that'd be a nice change.
Was This Post Helpful? 0
  • +
  • -

#44 jimblumberg  Icon User is offline

  • member icon

Reputation: 5333
  • View blog
  • Posts: 16,602
  • Joined: 25-December 09

Re: What is the main characteristic of pass-by-reference?

Posted 26 October 2017 - 09:04 AM

Quote

The catch is, I want to see valid arguments. The number of people believing one thing doesn't doesn't qualify as a valid argument(it would be a logical fallacy - they call it argumentum ad populum)


But the catch is that you would first need to get your selective reading disorder treated before anyone could even begin to give you a "valid argument". Even most of the "experts" that you have quoted disagree with your assertion (carefully read the quotes you provided), but that doesn't seem to register with you.

Perhaps this link may give you your "valid argument". And from that link:

Quote

The C/C++ technique for passing parameters is always the same, regardless of calling convention: All parameters are passed by value, except for arrays, which are translated into the address of the first member. To pass data by reference, pass a pointer to it.


Jim
Was This Post Helpful? 0
  • +
  • -

#45 snoopy11  Icon User is offline

  • Engineering ● Software
  • member icon

Reputation: 1376
  • View blog
  • Posts: 4,309
  • Joined: 20-March 10

Re: What is the main characteristic of pass-by-reference?

Posted 26 October 2017 - 10:32 AM

Yeah this,

Quote

Since everything is passed by value, nothing is passed by reference or any other thing. In other words. there's no such thing as pass by reference.

And that is troublesome statement, as it contradicts probably all books on C++ and many on C. '


No it doesn't and you never answered my question on this matter

Quote

What do you understand by the terms MDR and MAR


Well you might not like this but Im going to attempt to explain it you anyway...

at a hardware level this goes deeper than C although C hints at this structure..

it even goes deeper than Assembly although Assembly hints even more strongly at this structure..

but anyway I digress....

There are in modern computer design two memory registers or stores.

One holds the actual value of a thing ie a variable declared as X=3 in the MDR would be 3.
The other holds the actual address of where 3 is stored this is a memory location but it has a value ie a number it could be hypothetically H7800 but it depends on the machine.. its immaterial it stores addresses and is called the MAR..

when a command is given to the CPU it goes a bit like this... the commands a CPU can perform are simple two of the most important functions a CPU can carry out are 'fetch' and 'store' these are performed by selecting certain pins on the CPU and sending them high or low....

Depending on the manufacturer of the CPU and general computer design..

when a fetch command is issued H7800 is loaded into the MAR in binary and the 3 is retrieved from the memory location and copied into the MDR this is now ready for CPU operations these could arithmetic or bitwise operations but the 3 is now in two locations its at the memory address that is stored in the MAR and its loaded into the MDR ready for CPU operations

To be clear the MAR is a list of memory addresses ie ram locations and the MDR fetches and stores these values at memory locations depending on CPU operation.

What does all this actually mean when related to the pass by reference or pass by value argument that you are having with yourself...

well pass by value relates to the 3 stored at memory location H7800 in ram...
while pass by reference relates to value stored in the MAR that value is H7800 so it is said to point to the location of where the 3 is stored.

So now you see it clear both store values the pass by value stores 3 and the pass by reference stores H7800

So whats the point of pass by reference then if its a value ?

Well its not the value 3 its the value H7800 which is the memory location of where 3 is stored but its only the value of where the 3 is stored not the actual location so we can change the 3 into a 9 which is performed by a completely different memory register ie the MDR and if we are just pointing at this location when the CPU performs a fetch operation we get a 9 back not a 3 anymore.

This is incredibly useful as you can imagine for passing data into and out of functions we can just pass by reference and whatever we do on the actual value it doesnt matter because the reference is pointing at a memory location... but both are values both the 3 and the memory location H7800 are values because its all a computer can work in...

Computers are not some mystical object.... they are science and mathematics made wonderfully into a useful thing. They need numbers and the pointer is a number which relates to memory location of where a 'value' is stored but both are numbers both are values.. just in different parts of the computers memory registers.
Was This Post Helpful? 0
  • +
  • -

  • (11 Pages)
  • +
  • 1
  • 2
  • 3
  • 4
  • 5
  • Last »