It's worse than I thought
Walter Bright
newshound1 at digitalmars.com
Fri Nov 30 02:52:33 PST 2007
Janice Caron wrote:
> It's worse than I thought. This compiles and runs, both in D2.007 and in D2.008
>
> void main()
> {
> const(int) ci = 1;
> invariant(int) ii = 2;
>
> ++ci;
> ++ii;
> }
>
> It is now becoming quite clear that the "const mess" is very much
> still with us, and this sort of thing really doesn't help D at all.
It turns out that making a variable that is typed const (rather than
storage class const) immutable makes it impossible to use const references:
class C { }
const(C) c;
if (...)
c = ...;
else
c = ...;
So, variables that are typed const are rebindable. Note that this
doesn't break const, as you can always make a copy of a const. To get a
non-rebindable const:
const C c;
More information about the Digitalmars-d
mailing list