Author Topic: tiny problem for cc  (Read 7173 times)

Offline blueshake

  • Regular
  • ***
  • Posts: 459
tiny problem for cc
« on: February 11, 2010, 04:30:13 am »
hi,guys

I see that some codes in cc like this one.

e.g.

Code
void functionname (const classname& var)
{
      classname localvar = var;
     ......

}



here,in the function body functionname, why it make a copy for "var".


if want to make a copy for "var",why not use it in this way??

Code
void functionname (const classname var)
{
      //classname localvar = var;
     ......

}

correct me if I am wrong,thanks.
Keep low and hear the sadness of little dog.
I fall in love with a girl,but I don't dare to tell her.What should I do?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13438
    • Travis build status
Re: tiny problem for cc
« Reply #1 on: February 11, 2010, 09:41:53 am »
Why do you care?
Some people say that the second way of doing it might be faster ( http://cpp-next.com/archive/2009/08/want-speed-pass-by-value/ ).
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline blueshake

  • Regular
  • ***
  • Posts: 459
Re: tiny problem for cc
« Reply #2 on: February 11, 2010, 10:11:51 am »
Thanks for your reply. :D

I am going to rewrite the cc search function,but I see that in some funciton body it make a copy for the function arguments,I dont know why it was used here,
e.g.

the function arguments (var) here.
is it relatived to something(like thread-safe or else)? :D

if not,I will omit it in my new cc search function. :D
Keep low and hear the sadness of little dog.
I fall in love with a girl,but I don't dare to tell her.What should I do?

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: tiny problem for cc
« Reply #3 on: February 11, 2010, 05:18:43 pm »
RVO optimization capability is very limited!

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: tiny problem for cc
« Reply #4 on: February 12, 2010, 11:15:03 am »
There might be no particular reason at all, or it might be not wanting to change the function's signature for SDK compatibility at a later time.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."