I’m trying to figure out what actually happens in C++ if you return a struct by value from a function, vs. return a pointer to the struct. How is a struct communicated when its sent by value if a function can only return a value that can fit in a register? (I read that somewhere.)
I tried testing it on Godbolt to see what it’s doing. But I don’t understand the assembly so that was a bit optimistic of me.
It does look to me without much assembly knowledge that the function is just changing some memory that exists before the function is called? So then the concept of
returning something from a function is just an abstraction and the function is just setting some bytes in a memory location that already exists and then end jumping back to
main()? In which case nothing is copied at all and the return is
Source: Windows Questions C++