A new instance of a variable?

2015-11-13 Thread Ish via Digitalmars-d-learn
foreach (i; 0..5) { immutable int j = i; etc. } I want each j to be assigned separate memory so that it can be passed to a calle function and not overwritten by next value of i in foreach()??

Re: A new instance of a variable?

2015-11-13 Thread Alex Parrill via Digitalmars-d-learn
On Friday, 13 November 2015 at 15:49:01 UTC, Ish wrote: foreach (i; 0..5) { immutable int j = i; etc. } I want each j to be assigned separate memory so that it can be passed to a calle function and not overwritten by next value of i in foreach()?? Just like in C, you'll have to allocate

Re: A new instance of a variable?

2015-11-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/13/15 10:48 AM, Ish wrote: foreach (i; 0..5) { immutable int j = i; etc. } I want each j to be assigned separate memory so that it can be passed to a calle function and not overwritten by next value of i in foreach()?? This is not safe to do. What you are doing is passing a scope-a

Re: A new instance of a variable?

2015-11-13 Thread Ish via Digitalmars-d-learn
On Friday, 13 November 2015 at 16:06:51 UTC, Alex Parrill wrote: On Friday, 13 November 2015 at 15:49:01 UTC, Ish wrote: foreach (i; 0..5) { immutable int j = i; etc. } I want each j to be assigned separate memory so that it can be passed to a calle function and not overwritten by next val

Re: A new instance of a variable?

2015-11-13 Thread Marc Schütz via Digitalmars-d-learn
On Friday, 13 November 2015 at 17:44:31 UTC, Ish wrote: On Friday, 13 November 2015 at 16:06:51 UTC, Alex Parrill wrote: On Friday, 13 November 2015 at 15:49:01 UTC, Ish wrote: foreach (i; 0..5) { immutable int j = i; etc. } I want each j to be assigned separate memory so that it can be p

Re: A new instance of a variable?

2015-11-13 Thread anonymous via Digitalmars-d-learn
On 13.11.2015 18:44, Ish wrote: immutable int* j = new immutable int(i); gives error: locks1.d:27: error: no constructor for immutable(int); Looks like your D version is rather old. I had to go back to dmd 2.065 to see that error. 2.065 is from February 2014. We're at 2.069 now. I'd recommend

Re: A new instance of a variable?

2015-11-13 Thread Ish via Digitalmars-d-learn
On Friday, 13 November 2015 at 18:10:38 UTC, Marc Schütz wrote: On Friday, 13 November 2015 at 17:44:31 UTC, Ish wrote: On Friday, 13 November 2015 at 16:06:51 UTC, Alex Parrill wrote: [...] immutable int* j = new immutable int(i); gives error: locks1.d:27: error: no constructor for immutable