First Draft: ref For Variable Declarations

Walter Bright newshound2 at digitalmars.com
Thu May 2 06:58:43 UTC 2024


I forgot to mention: ref's are not rebindable:

```
void test(int i, int j)
{
     ref int r = i; // r cannot be rebound to j
}
```
This has an interesting consequence. The lifetime of the ref will always be less 
than the lifetime of what it was bound to.

```
ref int r = i;
{
     int j;
     r = j; // nope, cannot bind r to j
}
```

```
int i;
{
     ref int r = i; // r has shorter lifetime than i
}
```

which makes for more safety.


More information about the dip.development mailing list