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
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
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
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(," 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
a = a + 1
a is const, a + 1 is const, yet a can't be assigned to a + 1. And
I think the reason is like...
const(int) a = 23;
while(something()) {
a = a + 1;
}
in the first iteration, a is set to 23, and the value of "a + 1"
is 24, but where is the computer gonna store that 24? It can't