3 ms·
Clang produces identical code between C++ and C: https://gcc.godbolt.org/z/vWqn4s5ev https://gcc.godbolt.org/z/vWqn4s5ev I don't think that C disallows RVO, g
by flohofwoe 6y ago
Clang produces identical code between C++ and C:
https://gcc.godbolt.org/z/vWqn4s5ev https://gcc.godbolt.org/z/vWqn4s5ev
I don't think that C disallows RVO, gcc just might be more conservative there (maybe because of special Linux requirements)?
- jcelerier 6y ago> I don't think that C disallows RVO, optimizations should never change the output of a program unless explicitely allowed (the as-if rule). In c++ since RVO is allowed, it is ok for intptr_t value = 0; struct foo f() { struct foo the_foo; value = (intptr_t)&the_foo; return the_foo; } int main() { struct foo the_foo = f(); assert(value == (intptr_t)&the_foo); } to assert or not depending on the -O level. But I'd wager that it is not the case in C.