Wednesday, May 2, 2012

10.27

Suppose that we wanted to state a rule that would make the C dangling reference created by the following function illegal:


int* dangle(void)
{
     int x;
     return &x;
}


Suppose that we decided to make the following statement: the address of a local variable cannot be a returned value and cannot be assigned to a nonlocal variable. 
(A) Can this rule be checked statically?
Yes


(B) Does this rule solve the problem of dangling references created by the use of a stack based environment?
Yes

No comments:

Post a Comment