Yet yet yet yet another thread about const and immutable.
Jonathan M Davis
jmdavisProg at gmx.com
Tue Oct 25 09:39:46 PDT 2011
On Tuesday, October 25, 2011 09:05 Gor Gyolchanyan wrote:
> Why isn't it going to? The potential very powerful use of const is
> restricted because of this little misfeature. Declaring const
> variables instead of immutable variables has no advantage currently.
As I said, casting away const and modifying a variable is _undefined_ by the
language. D does not support logical const using const. Period. And there's no
reason why declaring a value type variable on the stack const should have any
advantage over declaring it immutable. In neither case is the variable going
to be modified without subverting the type system, and the compiler is free to
make whatever optimizations that it can based on that fact. The primary
differences between const and immutable show themselves when dealing with
stuff on the heap.
http://stackoverflow.com/questions/4219600/logical-const-in-d
- Jonathan M Davis
More information about the Digitalmars-d
mailing list