New to C++ and trying to learn optimization techniques, so hopefully someone can clarify for me.
Is there a real difference between these two options:
1) Store parameters and pass to function
const char *text = getText(var)
doSomething(text);
2) Pass to function calls for parameters
doSomething(getText(var));
I am not trained enough in computer science to realize the difference when it gets to the compiler stage, unfortunately, so any help would be great!
There is a technical difference: In
doSomething(getText(var));
the argument to doSomething
is an rvalue, while in
doSomething(text);
The argument is an lvalue. However, in the vast majority of all cases this is irrelevant, and both lines should result in equivalent machine code on any decent compiler, so choose whatever you find to be more readable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With