Re: If I understand const right...

2016-03-23 Thread ag0aep6g via Digitalmars-d-learn
On 23.03.2016 22:26, ag0aep6g wrote: On 23.03.2016 22:18, cy wrote: On Wednesday, 23 March 2016 at 21:10:49 UTC, ag0aep6g wrote: [...] b = new int(*b + 1); Here "b" is pointing to mutable heap allocated data, which got cast to constant. with b = b + 1, it's still constant memory. It's stac

Re: If I understand const right...

2016-03-23 Thread ag0aep6g via Digitalmars-d-learn
On 23.03.2016 22:18, cy wrote: On Wednesday, 23 March 2016 at 21:10:49 UTC, ag0aep6g wrote: [...] b = new int(*b + 1); Here "b" is pointing to mutable heap allocated data, which got cast to constant. with b = b + 1, it's still constant memory. It's stack memory. Its constness isn't any more

Re: If I understand const right...

2016-03-23 Thread cy via Digitalmars-d-learn
On Wednesday, 23 March 2016 at 21:10:49 UTC, ag0aep6g wrote: Just to be 100% clear: you're adding to the pointer here, No, that's what I meant to do. b = new int(*b + 1); Here "b" is pointing to mutable heap allocated data, which got cast to constant. with b = b + 1, it's still constant me

Re: If I understand const right...

2016-03-23 Thread ag0aep6g via Digitalmars-d-learn
On 23.03.2016 21:52, cy wrote: const(int)[2] a = [23,24]; const(int)* b = a; Should be: const(int)* b = a.ptr; writeln(&a," always constant"); writeln(a, " always constant"); There's some subtlety here. `a` itself is not const, but its elements are. `a` being a fixed-sized array, you can't