Yet yet yet yet another thread about const and immutable.

Gor Gyolchanyan gor.f.gyolchanyan at gmail.com
Tue Oct 25 09:05:38 PDT 2011


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.

On Tue, Oct 25, 2011 at 7:51 PM, Jonathan M Davis <jmdavisProg at gmx.com> wrote:
> On Tuesday, October 25, 2011 19:33:01 Gor Gyolchanyan wrote:
>> Nobody answered my question:
>> Why isn't const guaranteed to be placed in mutable storage?
>> It won't take advantages of immutable anyway, so why isn't it taking
>> advantages of potential logical const?
>
> Logical const is not supported by the language. Casting away const and
> modifying a variable is undefined. As such, the language is free to treat a
> const and immutable value type on the stack identically. There is no real
> difference. True, there's a decent chance that the compiler will generate
> slightly different code depending on what the code's doing, but it doesn't have
> to. Modifying the variable is undefined in either case. The language is _not_
> going to do anything to try and support the modifying of a const variable.
>
> - Jonathan M Davis
>


More information about the Digitalmars-d mailing list