On Thursday, 11 August 2016 at 08:53:22 UTC, John Colvin wrote:
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?

ping on this? I want to understand what's going on here and be another set of eyes checking for mistakes, but I'm stuck on this bit of the spec.

Reply via email to