static array internal & dangling reference
Picaud Vincent via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Nov 14 10:10:41 PST 2016
On Monday, 14 November 2016 at 17:15:43 UTC, Steven Schveighoffer
wrote:
> What has happened is that the stack allocated for f() (and
> since released) is still referenced by sb[]. In a weird way,
> since you haven't called any other functions, that data is
> still "valid"!
Thank you for the clarification. I am convinced, I think this is
the "true" reason why Valgrind does not react.
> I'm not sure what valgrind uses to determine what data is
> uninitialized or allocated, but in a very real sense, this code
> is deterministic, and will always result in the same result. Is
> it good practice? No. It's very fragile, and would break as
> soon as you called another function or reallocated that stack
> space (as your second example shows).
I understand you, and for sure this is not a good practice.
I think it is time for me to ruminate on something else...
Thank you
- Vincent
More information about the Digitalmars-d-learn
mailing list