Re: why local variables cannot be ref?

2019-11-25 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Nov 25, 2019 at 08:39:08PM +, Fanda Vacek via Digitalmars-d-learn wrote: > On Monday, 25 November 2019 at 08:32:53 UTC, H. S. Teoh wrote: > > On Mon, Nov 25, 2019 at 08:07:50AM +, Fanda Vacek via > > Digitalmars-d-learn wrote: [...] > > > But anyway, pointers are not allowed in

Re: why local variables cannot be ref?

2019-11-25 Thread Fanda Vacek via Digitalmars-d-learn
On Monday, 25 November 2019 at 09:00:49 UTC, Dukc wrote: On Monday, 25 November 2019 at 03:07:08 UTC, Fanda Vacek wrote: Is this preferred design pattern? ``` int main() { int a = 1; //ref int b = a; // Error: variable `tst_ref.main.b` only parameters or `foreach` declarations can be

Re: why local variables cannot be ref?

2019-11-25 Thread Fanda Vacek via Digitalmars-d-learn
On Monday, 25 November 2019 at 08:32:53 UTC, H. S. Teoh wrote: On Mon, Nov 25, 2019 at 08:07:50AM +, 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

Re: why local variables cannot be ref?

2019-11-25 Thread Timon Gehr via Digitalmars-d-learn
On 25.11.19 10:00, Dukc wrote: On Monday, 25 November 2019 at 03:07:08 UTC, Fanda Vacek wrote: Is this preferred design pattern? ``` int main() { int a = 1; //ref int b = a; // Error: variable `tst_ref.main.b` only parameters or `foreach` declarations can be `ref` ref int b() {

Re: why local variables cannot be ref?

2019-11-25 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, November 25, 2019 1:32:53 AM MST H. S. Teoh via Digitalmars-d- learn wrote: > On Mon, Nov 25, 2019 at 08:07:50AM +, Fanda Vacek via > Digitalmars-d-learn wrote: [...] > > > But anyway, pointers are not allowed in @safe code, so this is not > > always solution. > > [...] > > This is

Re: why local variables cannot be ref?

2019-11-25 Thread Dukc via Digitalmars-d-learn
On Monday, 25 November 2019 at 03:07:08 UTC, Fanda Vacek wrote: Is this preferred design pattern? ``` int main() { int a = 1; //ref int b = a; // Error: variable `tst_ref.main.b` only parameters or `foreach` declarations can be `ref` ref int b() { return a; } b = 2;

Re: why local variables cannot be ref?

2019-11-25 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Nov 25, 2019 at 08:07:50AM +, 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

Re: why local variables cannot be ref?

2019-11-25 Thread rumbu via Digitalmars-d-learn
On Monday, 25 November 2019 at 08:20:59 UTC, rumbu wrote: On Monday, 25 November 2019 at 08:07:50 UTC, Fanda Vacek wrote: Thanks for answer, I'm coming from C++. But anyway, pointers are not allowed in @safe code, so this is not always solution. Workaround exits even for @safe code, so my

Re: why local variables cannot be ref?

2019-11-25 Thread rumbu via Digitalmars-d-learn
On Monday, 25 November 2019 at 08:07:50 UTC, Fanda Vacek wrote: Thanks for answer, I'm coming from C++. But anyway, pointers are not allowed in @safe code, so this is not always solution. Workaround exits even for @safe code, so my question remains the same. What is a rationale for such a

Re: why local variables cannot be ref?

2019-11-25 Thread Fanda Vacek via Digitalmars-d-learn
On Monday, 25 November 2019 at 05:51:31 UTC, Rumbu wrote: On Monday, 25 November 2019 at 03:07:08 UTC, Fanda Vacek wrote: Maybe I'm missing the thing, but I'm not able to declare local ref variable even if simple workaround exists. Is this preferred design pattern? ``` int main() {

Re: why local variables cannot be ref?

2019-11-24 Thread Rumbu via Digitalmars-d-learn
On Monday, 25 November 2019 at 03:07:08 UTC, Fanda Vacek wrote: Maybe I'm missing the thing, but I'm not able to declare local ref variable even if simple workaround exists. Is this preferred design pattern? ``` int main() { int a = 1; //ref int b = a; // Error: variable

why local variables cannot be ref?

2019-11-24 Thread Fanda Vacek via Digitalmars-d-learn
Maybe I'm missing the thing, but I'm not able to declare local ref variable even if simple workaround exists. Is this preferred design pattern? ``` int main() { int a = 1; //ref int b = a; // Error: variable `tst_ref.main.b` only parameters or `foreach` declarations can be `ref`