why local variables cannot be ref?

Fanda Vacek fanda.vacek at gmail.com
Mon Nov 25 20:39:08 UTC 2019


On Monday, 25 November 2019 at 08:32:53 UTC, H. S. Teoh wrote:
> On Mon, Nov 25, 2019 at 08:07:50AM +0000, Fanda Vacek via 
> Digitalmars-d-learn wrote: [...]
>> But anyway, pointers are not allowed in @safe code, so this is 
>> not always solution.
> [...]
>
> This is incorrect. Pointers *are* allowed in @safe code. 
> Pointer *arithmetic* is not allowed.
>
>
> --T

void main() @safe
{
	int a = 1;
	int *b = &a;
	*b = 2;
	assert(a == 2);
}

does not compile for me with Error: cannot take address of local 
`a` in `@safe` function `main`

so there must be more restrictions in @safe code

Fanda



More information about the Digitalmars-d-learn mailing list