D const design rationale

Sean Kelly sean at f4.ca
Fri Jun 22 08:43:03 PDT 2007


Daniel Keep wrote:
> 
> Frits van Bommel wrote:
>> Leandro Lucarella wrote:
>>> Walter Bright, el 22 de junio a las 01:07 me escribiste:
>>>> Sean Kelly wrote:
>>>>> Walter Bright wrote:
>>>>>> http://www.digitalmars.com/d/const.html
>>>>> So in short, 'const' protects data and 'final' freezes references. 
>>>>> How do these two apply to an int declaration?
>>>>>    const final int x = 5;
>>>>> Is either a compiler error? are they synonyms in this case?
>>>> It's not an error, it's just redundant.
>>> Shouldn't be better to be an error? So it's more clear that final makes
>>> sense only for reference types.
>> Allowing it allows cleaner generic code, otherwise templates would often
>> have to check whether parameters were value or reference types.
> 
> Indeed; we already need to special-case functions that return void.

How so?  I thought "return void" was a legal statement?


Sean



More information about the Digitalmars-d mailing list