'in' storage class
Jason House
jason.james.house at gmail.com
Thu Sep 6 14:57:26 PDT 2007
Funog wrote:
> Robert Fraser Wrote:
>
>> Funog Wrote:
>>
>>> Nathan Reed Wrote:
>>>
>>>> Funog wrote:
>>>>> void testFinal(final int[] foo)
>>>>> {
>>>>> foo[0] = 10; //OK
>>>>> foo = new int[20]; //ERROR
>>>>> }
>>>>> void testConst(const int[] foo)
>>>>> {
>>>>> foo[0] = 10; //ERROR
>>>>> foo = new int[20]; //ERROR
>>>>> }
>>>>> void testFinalConst(final const int[] foo)
>>>>> {
>>>>> foo[0] = 10; //ERROR
>>>>> foo = new int[20]; //ERROR
>>>>> }
>>>>>
>>>>>
>>>>> So what is the difference between 'const' and 'final const' ?
>>>>>
>>>> I suppose there's no practical difference in that case since you're
>>>> using the transitive const. Note that final const(int)[] foo is
>>>> different from const(int)[] foo though.
>>>>
>>>> Thanks,
>>>> Nathan Reed
>>>
>>>
>>> I agree... But then, what is the point of having 'in' equivalent to 'final const scope' rather than just 'const scope' ?
>>>
>> The difference is easier for me to grasp when talking about class references than arrays.
>>
>> class Foo { int bar; }
>>
>> final Foo baz;
>> baz.bar = 5; // Okay
>> baz = quux; // Illegal
>>
>> const Foo quux; // Equivilent, I _think_ to const(Foo) quux;
>> quux.bar = 5; // Illegal
>> quux = baz; //Okay
>>
>
>
> It isn't... Both lines are illegal. quux = baz is legal for const(Foo) quux.
> If nobody can tell the difference between "const scope" and "in" ( = final const scope ), should we report it as a bug ? xD
>
If I understand stuff right, "quux = baz;" should be legal. Use of quux
thereafter, including reassigning quux, does not invalidate baz's use of
final. I have not tested this with a compiler, of course...
More information about the Digitalmars-d-learn
mailing list