Hacker News new | ask | show | jobs
by haiihaii 3002 days ago
I've gotten quite used to doing just this. It started out as a habit from cpp where I relied on RVO, but for small structs the price of copying it vs copying a pointer to it seems extremely minimal apart from the temporary double allocation. Also, does anyone know if gcc or clang does something along the lines of RVO behind the scenes? I fail to see any side effects from it, so it should be entirely possible, no?
1 comments

It really depends on the target architecture (and ABI), size of the struct and how fields in the struct are defined, more than if it's C or C++. For simple examples like this one: https://godbolt.org/g/ZT3bJ3 there usually will be no problem.