What guarantees does D 'const' provide, compared to C++?
Jonathan M Davis
jmdavisProg at gmx.com
Sat Aug 18 09:59:13 PDT 2012
On Saturday, August 18, 2012 13:25:56 Peter Alexander wrote:
> In D, const without immutable is meaningless.
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).
- Jonathan M Davis
More information about the Digitalmars-d
mailing list