News for hackers. Stuff that matters.
Re:Modern C++ for C Programmers: part 5 by SidiousL on Wednesday July 25, 2018 @12:38PM (#17610583)
I tried to find an example that contradicts what you said, but I can't find any. Here's an online example which can be compiled as both C and C++ and I obtain exactly the same assembly using both clang and gcc. Maybe somebody can tweak this example to force the C compiler not to perform the optimization.

https://godbolt.org/g/7Ewun7

Re:Modern C++ for C Programmers: part 5 by BeeOnRope on Wednesday July 25, 2018 @05:51PM (#17613217)
See my reply to the parent poster for an example where RVO applies in C++ but not C, leading to better code in the C++ case. The key is to let the address of the objects involved escape: otherwise "as if" will let C (and C++ even without RVO) optimize away the copies anyways, since they are not observable in that case.