Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

implicit passing by reference

160 views
Skip to first unread message

jerry.j...@gmail.com

unread,
Feb 20, 2014, 11:45:27 PM2/20/14
to
In this topic

http://stackoverflow.com/questions/21924885/could-someone-please-just-tell-me-why-my-for-loop-will-not-count-all-the-way-u

The person that answers it says:

You have to remember that objects are sent to functions 'by reference'.

But the object being passed contains only one int member and the function the object is being passed to clearly takes it's parameter by value and stores it in a member value.

Do objects really always pass by reference regardless of what the parameter list says? And, if so, why would it do that? I would usderstand if the function took its parameter explicitly by reference...

Thanks for clearing up mu confusion.

Jerry

Paavo Helde

unread,
Feb 21, 2014, 12:42:57 AM2/21/14
to
jerry.j...@gmail.com wrote in
news:0f7c3e54-364c-4e62...@googlegroups.com:

> In this topic
>
> http://stackoverflow.com/questions/21924885/could-someone-please-just-
> tell-me-why-my-for-loop-will-not-count-all-the-way-u
>
> The person that answers it says:
>
> You have to remember that objects are sent to functions 'by
> reference'.
>
> But the object being passed contains only one int member and the
> function the object is being passed to clearly takes it's parameter by
> value and stores it in a member value.
>
> Do objects really always pass by reference regardless of what the
> parameter list says? And, if so, why would it do that? I would
> usderstand if the function took its parameter explicitly by
> reference...

In C++ the function declarations specify exactly if the pass is by value
or by reference. The people at stackoverflow probably have confused C++
with some other language. Do not take stackoverflow too seriously, the
answers there are ranked by the person least qualified to judge the
correctness.

Cheers
Paavo

Jorgen Grahn

unread,
Feb 21, 2014, 6:44:54 AM2/21/14
to
On Fri, 2014-02-21, Paavo Helde wrote:
> jerry.j...@gmail.com wrote in
> news:0f7c3e54-364c-4e62...@googlegroups.com:
>
>> In this topic
>>
>> http://stackoverflow.com/questions/21924885/could-someone-please-just-
>> tell-me-why-my-for-loop-will-not-count-all-the-way-u
>>
>> The person that answers it says:
>>
>> You have to remember that objects are sent to functions 'by
>> reference'.
>>
>> But the object being passed contains only one int member and the
>> function the object is being passed to clearly takes it's parameter by
>> value and stores it in a member value.
>>
>> Do objects really always pass by reference regardless of what the
>> parameter list says? And, if so, why would it do that? I would
>> usderstand if the function took its parameter explicitly by
>> reference...
>
> In C++ the function declarations specify exactly if the pass is by value
> or by reference.

Or you could say it's always by value -- but you can choose to pass a
reference or pointer to some object.

> The people at stackoverflow probably have confused C++
> with some other language.

Yes, and you have to be pretty confused to do that.
I tell my coworkers to avoid stackoverflow because of stuff like
this.

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .

Marcel Müller

unread,
Feb 21, 2014, 11:36:27 AM2/21/14
to
On 21.02.14 12.44, Jorgen Grahn wrote:
> On Fri, 2014-02-21, Paavo Helde wrote:
>> In C++ the function declarations specify exactly if the pass is by value
>> or by reference.
>
> Or you could say it's always by value -- but you can choose to pass a
> reference or pointer to some object.

Strictly speaking it is up to the platform how references are
implemented. The option that they are binary compatible to pointers is
only a common solution.

>> The people at stackoverflow probably have confused C++
>> with some other language.
>
> Yes, and you have to be pretty confused to do that.
> I tell my coworkers to avoid stackoverflow because of stuff like
> this.

Well, in general it is not that bad. But it is more the home of the .NET
guys (where the statement about objects is true) and like any other
forum it is no editorially approved content.


Marcel

88888 Dihedral

unread,
Feb 21, 2014, 4:28:26 PM2/21/14
to
Well, an object in C++ has some hidden
field to store the address of this object in the C sense.

Victor Bazarov

unread,
Feb 21, 2014, 4:39:18 PM2/21/14
to
On 2/21/2014 4:28 PM, 88888 Dihedral wrote:
>[...]
> Well, an object in C++ has some hidden
> field to store the address of this object in the C sense.

I will probably regret this later, but... What the hell do you mean?

V
--
I do not respond to top-posted replies, please don't ask

Osmium

unread,
Feb 21, 2014, 4:45:36 PM2/21/14
to
"Victor Bazarov" wrote:

> On 2/21/2014 4:28 PM, 88888 Dihedral wrote:
>>[...]
>> Well, an object in C++ has some hidden
>> field to store the address of this object in the C sense.
>
> I will probably regret this later, but... What the hell do you mean?

Now you did it. You reactivated him after a long dormant period.


Victor Bazarov

unread,
Feb 21, 2014, 5:43:53 PM2/21/14
to
I did? Damn... I thought he was replying to Paavo. Ah, no matter.
Sorry! My fault! I really regret this! Etc. etc.

red floyd

unread,
Feb 21, 2014, 6:20:56 PM2/21/14
to
On 2/21/2014 2:43 PM, Victor Bazarov wrote:

> I did? Damn... I thought he was replying to Paavo. Ah, no matter.
> Sorry! My fault! I really regret this! Etc. etc.
>

You are hereby sentenced to 200 hours of listening to Justin Bieber
albums.


Paavo Helde

unread,
Feb 21, 2014, 6:48:26 PM2/21/14
to
Victor Bazarov <v.ba...@comcast.invalid> wrote in news:le8kr9$trj$1@dont-
email.me:

> On 2/21/2014 4:45 PM, Osmium wrote:
>> "Victor Bazarov" wrote:
>>
>>> On 2/21/2014 4:28 PM, 88888 Dihedral wrote:
>>>> [...]
>>>> Well, an object in C++ has some hidden
>>>> field to store the address of this object in the C sense.
>>>
>>> I will probably regret this later, but... What the hell do you mean?
>>
>> Now you did it. You reactivated him after a long dormant period.
>
> I did? Damn... I thought he was replying to Paavo. Ah, no matter.
> Sorry! My fault! I really regret this! Etc. etc.

Yes, sorry, seems to be my fault. Must have been some special combination
of letters I guess ;-)

"In C++ the function declarationS specify exAcTly if the pAss is by value
or by reference. The people at stackoverflow probably have coNfused C++
with some other lAnguage. Do not take stackoverfloW too seriously, the
Answers there are ranKed by the pErson least qualified to judge the
correctness."

P.

Ian Collins

unread,
Feb 21, 2014, 7:21:07 PM2/21/14
to
That, being a cruel and inhumane punishment, would be considered a
breach of Victor's human rights by the European court :)

--
Ian Collins

Victor Bazarov

unread,
Feb 21, 2014, 7:47:48 PM2/21/14
to
I still probably deserve it. Besides, I don't reside in the
jurisdiction of the European court :-[

red floyd

unread,
Feb 22, 2014, 1:40:21 AM2/22/14
to
On 2/21/2014 4:47 PM, Victor Bazarov wrote:
> On 2/21/2014 7:21 PM, Ian Collins wrote:
>> red floyd wrote:
>>> On 2/21/2014 2:43 PM, Victor Bazarov wrote:
>>>
>>>> I did? Damn... I thought he was replying to Paavo. Ah, no matter.
>>>> Sorry! My fault! I really regret this! Etc. etc.
>>>>
>>>
>>> You are hereby sentenced to 200 hours of listening to Justin Bieber
>>> albums.
>>
>> That, being a cruel and inhumane punishment, would be considered a
>> breach of Victor's human rights by the European court :)
>
> I still probably deserve it. Besides, I don't reside in the
> jurisdiction of the European court :-[

Just giving you a hard time, Victor. The opportunity was too good
to pass up. :-D


Jorgen Grahn

unread,
Feb 22, 2014, 3:25:09 AM2/22/14
to
On Fri, 2014-02-21, Marcel Müller wrote:
> On 21.02.14 12.44, Jorgen Grahn wrote:
>> On Fri, 2014-02-21, Paavo Helde wrote:
>>> In C++ the function declarations specify exactly if the pass is by value
>>> or by reference.
>>
>> Or you could say it's always by value -- but you can choose to pass a
>> reference or pointer to some object.
>
> Strictly speaking it is up to the platform how references are
> implemented. The option that they are binary compatible to pointers is
> only a common solution.

Of course. Note that I didn't imply that references are pointers --
just that both can be used if you want "pass by reference" semantics.

James Kanze

unread,
Feb 23, 2014, 9:13:29 AM2/23/14
to
On Friday, February 21, 2014 5:42:57 AM UTC, Paavo Helde wrote:

> Do not take stackoverflow too seriously, the
> answers there are ranked by the person least qualified to judge the
> correctness.

You've noticed that too. The highest ranked answers are rarely
the correct ones.

--
James

James Kanze

unread,
Feb 23, 2014, 9:16:23 AM2/23/14
to
It's harder to do if you work in an investment bank, where NNTP
is blocked by the firewall, as is Google Groups. (I have yet to
figure out the reasoning behind it, but it seems to be some
legal requirement, since it is univeral, at least in London
banks.)

--
James
Message has been deleted

jerry.j...@gmail.com

unread,
Feb 23, 2014, 4:10:19 PM2/23/14
to
On Friday, February 21, 2014 6:42:57 PM UTC+13, Paavo Helde wrote:
>
> In C++ the function declarations specify exactly if the pass is by value or by reference. The people at stackoverflow probably have confused C++ with some other language. Do not take stackoverflow too seriously, the answers there are ranked by the person least qualified to judge the correctness.
>
> Cheers
>
> Paavo

I *knew* it was wrong. What I didn't know what that stackoverflow was so unreliable (I have had good luck until now)

Thanks very much for all the advice.

Jerry

Paavo Helde

unread,
Feb 23, 2014, 6:14:02 PM2/23/14
to
jerry.j...@gmail.com wrote in
news:65747709-69b4-44bb...@googlegroups.com:

> What I didn't know what that stackoverflow was
> so unreliable (I have had good luck until now)

I have asked some questions myself there, and the system soon insisted me
me to select THE answer. How would I know which, if any, of the proposed
third-party libraries is of any good? It becomes clear only after a couple
of years of eperience, possibly only after when the poor
customers^H^H^H^H^H^H^H^H^Hbeta-testers have filed their multi-threading
and other bug reports.

Cheers
Paavo




Daniel

unread,
Feb 23, 2014, 10:30:08 PM2/23/14
to
On Sunday, February 23, 2014 9:13:29 AM UTC-5, James Kanze wrote:
>
> The highest ranked answers are rarely the correct ones.
>
Speaking as someone with a stackoverflow reputation of 81,234, so some votes must have hit the target :-)

Daniel

Stuart

unread,
Feb 24, 2014, 5:57:19 AM2/24/14
to
On 02/23/14, Stefan Ram wrote:
>
> Read the post »Welcome Slashdot refugees!« of February 6 in
> the newsgroup »comp.misc« and the following posts to witness
> the return of Slashdot users to Usenet.
>

I took your advice and I stumbled upon this posting,
<ldcp5b$ct9$1...@speranza.aioe.org>, where the poster said that newsgroups
needed somehow be improved by some rating system in order to sort out
irrelevant or rather uninteresting postings.

I don't think that this is necessary. If you follow the newsgroup for a
while, you get to know people. Whenever I see either Alf, Bart, Bo, Ian,
James Kanze, Jorgen, Joshua Cramner, Juha, Paavo, Öö, yourself, Tobias
Müller, Ulrich, or Victor (in alphabetical order), I know that this
posting is worth reading.

Brian, Quall, and even Mr. Flibble make some interesting contributions,
although these are often buried in a mass of off-topic ramblings.

Regards,
Stuart

88888 Dihedral

unread,
Mar 9, 2014, 6:57:21 PM3/9/14
to

> Yes, and you have to be pretty confused to do that.
>
> I tell my coworkers to avoid stackoverflow because of stuff like
>
> this.

Well, it is not clear in your
descriptions of the stack model
of atuto variables and objs in C++.

Anyway, the objs in derived classes used by compiled codes to perform
assignment and copying operations
in C++ are really tricky in the syntax.
0 new messages