cannot take address of scope local in safe function

vit vit at vit.vit
Sun Jun 13 16:27:18 UTC 2021


Why I can take address of Foo variable but not Bar?

```d
//-dip1000

struct Foo{
     private double d;
}

struct Bar{
     private void* ptr;
}



void main()@safe{
     ///this is OK:
     {
         scope Foo x;
         scope ptr = &x;
     }

     ///Error: cannot take address of `scope` local `x` in `@safe` 
function `main`:
     {
         scope Bar x;
         scope ptr = &x;
     }
}
```


More information about the Digitalmars-d-learn mailing list