#include int f1() { L: { int x = 0; int *`L p = &x; if(true) { L2: { int y = 0; int *`L2 q = &y; int z = *p + *q; // okay because `L and `L2 name live regions // p = q; // not allowed -- type mismatch (C compiler would allow) } } return *p; // would be dangling if we assigned q to p } } int f2() { int x = 0; int * p = &x; if(true) { int y = 0; int * q = &y; int z = *p + *q; // okay because `L and `L2 name live regions // p = q; // not allowed -- type mismatch (C compiler would allow) } return *p; // would be dangling if we assigned q to p // return p; // dangling no matter what (change return type to int*??) } int*`r inc_and_return<`r>(int*`r p) { *p=(*p) + 1; return p; } int g = 9; void f3() { L: { int x = 17; int *`L p1 = inc_and_return@<`L>(&x); int *`H p2 = inc_and_return@<`H>(&g); } } void f4() { int x = 17; int * p1 = inc_and_return(&x); int * p2 = inc_and_return(&g); } void f5(int i, int j) { region r; // create region, r is the handle for(; i >= 0; --i) rcalloc(r,j,sizeof(int)); // create int[10] array for no reason } char*`r2 compute_a_string(region_t<`r2> handle) { g = g*7/34 + 6; { char*`r2 ans = rcalloc(handle,g,sizeof(char)); // can initialize array to something other than '\0' chars here return ans; } } void f6() { region r; char *`r str = compute_a_string(r); // use str, which can have any length // on return string gets deallocated // if we need it longer, we can be passed a handle }