D const design rationale

Sean Kelly sean at f4.ca
Fri Jun 22 08:42:17 PDT 2007


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.

It shouldn't be an error.  With template functions, you often aren't 
sure what may be passed in, and may want to do something like this just 
to be safe:

void func(T)( const final T val ) { ... }



Sean



More information about the Digitalmars-d mailing list