Gotchas for returning values from blocks

Era Scarecrow via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jun 13 14:54:20 PDT 2016


On Monday, 13 June 2016 at 14:16:58 UTC, jmh530 wrote:
> So returning a reference to something on the stack is a bad 
> idea, but copying the value would be fine.

  This is easy enough to get wrong elsewhere too. I recall having 
an issue with a foreach, until I added a 'ref' to it. Looking at 
the addresses all pointing to the same spot (the temporary) which 
can add curiously subtle bugs, or blatantly obvious ones.


More information about the Digitalmars-d-learn mailing list