static array internal & dangling reference
cym13 via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Nov 13 09:52:02 PST 2016
On Saturday, 12 November 2016 at 12:16:02 UTC, Andrew wrote:
> On Saturday, 12 November 2016 at 11:03:31 UTC, Mike Parker
> wrote:
>>[...]
>
> I thought that if you changed the function signature to int[10]
> f() to return a static array, this should be returned by value,
> and so should be safe to use, but it seems that this too points
> to the same memory.
This is likely because your examples are too simple and the local
variables of each stack frame happen to be at the same place with
the same value. There's nothing really conclusive here.
> To make it safe, should I be using:
>
> auto sb = f().dup;
>
> Thanks
>
> Andrew
More information about the Digitalmars-d-learn
mailing list