DIP1000: Scoped Pointers (Discussion)

deadalnix via Digitalmars-d digitalmars-d at puremagic.com
Thu Aug 11 03:00:10 PDT 2016


On Thursday, 11 August 2016 at 08:29:37 UTC, John Colvin wrote:
> On Wednesday, 10 August 2016 at 20:36:38 UTC, Dicebot wrote:
>> Proposal text: 
>> https://github.com/dlang/DIPs/blob/master/DIPs/DIP1000.md
>
> Can someone talk me through the lifetime algebra for the 
> following?
>
> void foo()
> {
>     int a;
>     int** c;
>     void bar()
>     {
>         int* b = &a;
>         c = &b;
>     }
>     bar();
>     *c; //undefined behaviour
> }
>
> I think it's this:
>
> lifetime(a) = all of foo
> lifetime(c) = infinite (because null) //initially
> lifetime(b) = lifetime(&a) = lifetime(a) = all of foo // ????
> lifetime(c) = lifetime(&b) = lifetime(b) = all of foo //on 
> assignment in bar
>
> That would suggest that dereferencing c was OK, because the 
> lifetime is all of foo. What am I missing?

You are not missing anything. This DIP is flawed because it only 
handle on indirection level and break down for anything more than 
this.



More information about the Digitalmars-d mailing list