As I read about copy elision, many of the sources only mention C++ and not C.
They state how the C++ standard allows this optimization to take place if the compiler decides it is the right thing to do.
But what about C? Do C compilers perform copy elision, or does the C standard gaurentee that copies will never be optimized away?
Both C and C++ allow any optimizations that follow the as-if rule. Since C doesn't have constructors - and therefore constructors with side-effects- copies may be elided without breaking this rule. C++ on the other hand needs to make a special case where an implementation is allowed to break as-if.
So, copy elision exists in C implicitly through the as-if rule.
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