dip1000: why can't the addressee come into existence later?
Neia Neutuladh
neia at ikeran.org
Sun Nov 11 00:08:12 UTC 2018
On Sat, 10 Nov 2018 16:25:40 +0000, Stanislav Blinov wrote:
> Yep, you just over-simplified the first case.
It is too simple to clearly illustrate why the code is invalid, but not so
simple that the compiler accepts that code.
> Consider:
>
> int* p;
> {
> int i;
> p = &i;
> }
> *p = 42;
In that example, the scope for i ends before the scope for p ends. It's
not at all surprising that that code is wrong. In the other examples I
gave, both i and p go out of scope at the same time.
But there's a total ordering for when variables' lifetimes end, which is
the key (and non-obvious) difference between the two.
More information about the Digitalmars-d-learn
mailing list