Global const variables

Szymon Gatner via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Oct 21 02:22:21 PDT 2014


On Tuesday, 21 October 2014 at 08:48:09 UTC, safety0ff wrote:
> On Tuesday, 21 October 2014 at 08:25:07 UTC, bearophile wrote:
>> Minas Mina:
>>
>>> Aren't pure functions supposed to return the same result 
>>> every time? If yes, it is correct to not accept it.
>>
>> But how can main() not be pure? Or, how can't the 'a' array be 
>> immutable?
>>
>> Bye,
>> bearophile
>
> There can exist a mutable reference to a's underlying memory:
>
> const int[] a;
> int[] b;
>
> static this()
> {
>     b = [1];
>     a = b;
> }

Ant this code works? What is the point of const then if you can 
assign it to mutable slice?



More information about the Digitalmars-d-learn mailing list