D const design rationale

Walter Bright newshound1 at digitalmars.com
Fri Jun 22 11:17:34 PDT 2007


Leandro Lucarella wrote:
> Even more, aren't:
> 
> const int x = 5;
> final int x = 5;
> invariant int x = 5;
> 
> all the same?

No, because finals exist in memory, while const/invariants do not. 
Const/invariant declarations also require their initializers to be 
evaluated at compile time, whereas final can do them at run time.

The const & invariant cases are the same, as they are the degenerate 
cases. It's sort of like:

int x = 1;
uint y = 1;

both represent 1.



More information about the Digitalmars-d mailing list