Logical const
Max Samukha
spambox at d-coding.com
Tue Nov 30 03:25:21 PST 2010
On 11/30/2010 02:35 AM, Walter Bright wrote:
> Fawzi Mohamed wrote:
>> logical const is useful for lazy functions and memoization, and if
>> implemented correctly it is perfectly safe.
>> As I said in an older discussions, to have it with the current system
>> all that is needed is some guarantees that the compiler will not
>> disallow "unsafe" changes (by moving to read only memory for
>> example)in some cases.
>> For example casted mutable types, so that casting to mutable works.
>
> D allows escape from the type system, but the programmer who does that
> loses the guarantees, and it's up to him to ensure that the result works.
>
> String literals, for example, are going to often wind up in read only
> memory.
The problem is that logical const has many perfectly valid use cases.
You cannot simply tell people: "Don't use it. It is a fraud". They will
still be using casts or not using D. As casting away const is undefined
behavior in D, the outcome will be every second non-trivial D program
relying on undefined behavior.
More information about the Digitalmars-d
mailing list