3 ms·
That’s only true if the function takes no argument. Otherwise the copy on return is unavoidable.
by bugbuddy 3y ago
That’s only true if the function takes no argument. Otherwise the copy on return is unavoidable.
- pclmulqdq 3y agoThat's not actually true: https://en.cppreference.com/w/cpp/language/copy_elision https://en.cppreference.com/w/cpp/language/copy_elision
- gpderetta 3y agoI think parent is confused with NRVO typically not being triggered when returning a function argument.
- kukkamario 3y agoIn AMD64 ABI, anything larger (that doesn't fit in register) will be returned by basically output pointer argument. Caller reserves space for the return value and gives pointer to the function which then fills it with the return value. Both sides are easy to optimize and no unnecessary copies are made. Function can directly construct return value to the given address and caller can directly give a pointer to a variable if function return value is used to initialise variable.