[Issue 15842] struct is being copied when returned directly
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Thu Mar 31 11:21:03 PDT 2016
https://issues.dlang.org/show_bug.cgi?id=15842
hsteoh at quickfur.ath.cx changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords|wrong-code |
CC| |hsteoh at quickfur.ath.cx
--- Comment #1 from hsteoh at quickfur.ath.cx ---
I'm pretty sure this behaviour is according to spec. Structs are supposed to
behave like glorified ints, meaning they are value types and may be freely
copied around and moved when passing between functions. This is one reason
it's a bad idea to keep internal pointers to a struct, as the pointers will
become invalid once the struct is moved. Returning a struct from a function is
generally implemented as storing in a temporary area on the stack, and moving
to the final stack variable once control returns to the caller.
--
More information about the Digitalmars-d-bugs
mailing list