www.digitalmars.com         C & C++   DMDScript  

D - Re: const

reply Lio <Lio_member pathlink.com> writes:
Nevermind :-S I've missed it.. Just saw it in the docs. But no mutable?

L.
Oct 07 2003
parent "Sean L. Palmer" <palmer.sean verizon.net> writes:
D uses quite a different model for constness than C++.

In C++, const is a type modifier.  In D, const is a storage class.  D is
more like Pascal in this respect.  C++'s method is kinda flawed since const
is never a guarantee that the value will change, C++ compilers can't utilize
the information to do more optimizations.

Since D consts are true constants, they are totally unmodifiable.  Thus
there is no point to having "mutable".

However I don't think this system is perfect.  There are issues with it,
from what I can tell.  For one, there's no way to make variables appear
"readonly" to other parts of the code, yet remain writable to the class
itself (mutable would handle this, but then const would have to be a type
modifier).

Sean

"Lio" <Lio_member pathlink.com> wrote in message
news:blu0ru$2mbl$1 digitaldaemon.com...
 Nevermind :-S I've missed it.. Just saw it in the docs. But no mutable?

 L.
Oct 07 2003