News:

The new Release 25.03 is out! You can download binaries for Windows and many major Linux distros here .

Main Menu

tiny problem for cc

Started by blueshake, February 11, 2010, 04:30:13 AM

Previous topic - Next topic

blueshake

hi,guys

I see that some codes in cc like this one.

e.g.

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??

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?

oBFusCATed

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!]

blueshake

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?

Loaden

RVO optimization capability is very limited!

thomas

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."