const by default.
Deewiant
deewiant.doesnotlike.spam at gmail.com
Tue Jul 4 07:22:29 PDT 2006
BCS wrote:
> However if you are passing them to a function they become implicitly
> immutable unless you say otherwise. (Assume that "@" is the grant
> mutability operator)
>
> void fn4()
> {
> char[] c;
>
> c[5] = '\0'; // allowed
>
> fn1(c); // allowed
> fn2(c); // not allowed: arg 1 is mutable;
> fn2(@c) // allowed
> }
>
> In the general case I expect that this change will have little effect on
> code. In my experience, most pass by reference cases are immutable
> anyway. The rest should be easy to find and fix as long as DMD gives
> good error messages.
I think there's a problem with all this "grant mutability/immutability", which
is that we're just degenerating into C++ with its const_cast. With it, the
compiler has few, if any, guarantees about the constness of anything --- it can
always be casted away.
The way I see it, something either is or isn't mutable, and it should stay that
way for the duration of the program --- in some cases, for the duration of a
function or the lifetime of an object.
More information about the Digitalmars-d
mailing list