Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Development => CodeCompletion redesign => Topic started by: blueshake on February 11, 2010, 04:30:13 am

Title: tiny problem for cc
Post by: blueshake 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.
Title: Re: tiny problem for cc
Post by: oBFusCATed 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/ ).
Title: Re: tiny problem for cc
Post by: blueshake 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
Title: Re: tiny problem for cc
Post by: Loaden on February 11, 2010, 05:18:43 pm
RVO optimization capability is very limited!
Title: Re: tiny problem for cc
Post by: thomas 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.