What guarantees does D 'const' provide, compared to C++?

Walter Bright newshound2 at digitalmars.com
Sat Aug 18 12:12:36 PDT 2012


On 8/18/2012 9:59 AM, Jonathan M Davis wrote:
> That's not quite true. There _are_ cases where const by itself is enough to
> provide guarantees (and I give such an example elsewhere in this thread).
> However, the situations where that's the case are quite limited, because the
> compiler has to be able to know that no other references to that data exist.
> With pure added in, they increase considerably, and of course, with immutable,
> they're much, much higher, because it doesn't have to worry about figuring out
> whether other, mutable references to the data exist or not. But if the
> compiler knows that no other references to const data exist, then that's
> enough to make optimizations (though whether the compiler ever _does_ do that
> is another matter entirely).

You're quite right.




More information about the Digitalmars-d mailing list