const by default.
Walter Bright
newshound at digitalmars.com
Fri Jul 7 13:01:31 PDT 2006
BCS wrote:
> Walter Bright wrote:
> [...]
> > class C { int m; }
> > void bar(C c) { c.m = 3; } // ok
> [...]
>>
>> C foo(in C c) { return c; } // ok
>>
>> void foo(in C c) { bar(c); } // ok
>>
>> void foo(in C c)
>> { C d = c;
>> d.m = 3; // ok
>> }
>>
>
> How would the last three work?
The compiler would accept them, though I'd say it would be a bad
programming practice.
> IIRC, const implies that data is not
> accessible for writes. In the first of those three, the return value has
> no indication of const'ness so something like this could be done
That's right.
> What I want is a way to get an assurance by the compiler that a
> referenced value will not be changed. This would require that const
> references (or a non mutable ones) can never be made into a mutable
> references.
>
> If I'm missing something, please point it out.
You haven't missed something. The 'in' thing proposed above is not an
airtight guarantee, you could call it more of a 'sieve'. It's more of a
documentation aid. The compiler checking would be minimal and easily
subverted.
More information about the Digitalmars-d
mailing list