DIP1000: Scoped Pointers (Discussion)
John Colvin via Digitalmars-d
digitalmars-d at puremagic.com
Thu Aug 11 01:53:22 PDT 2016
On Thursday, 11 August 2016 at 08:45:38 UTC, Walter Bright wrote:
> On 8/11/2016 1:29 AM, John Colvin wrote:
>> Can someone talk me through the lifetime algebra for the
>> following?
>>
>> void foo()
>> {
>> int a;
>> int** c;
>> void bar()
>> {
>> int* b = &a; <= ok, b has a smaller lifetime than a
>> c = &b; <= error, c has a larger lifetime than b
>> }
>> bar();
>> *c; //undefined behaviour
>> }
but according to this rule:
"For an unrestricted pointer, visibility is dictated by the usual
lexical scope rules. Lifetime, however is dictated by the
lifetime of the data to which the pointer points to."
b should have the same lifetime as a, no?
More information about the Digitalmars-d
mailing list