const

Bruno Medeiros brunodomedeiros+spam at com.gmail
Sun Apr 27 11:47:20 PDT 2008


Janice Caron wrote:
> 
> Perhaps, but I don't think you've understood that it is /impossible/
> to declare a const variable that isn't, in fact, invariant. Consider:
> 
>     const int x = 5;
> 
> x may be typed const(int), but it is, in fact, really, really,
> invariant. Because not only can you not change it, but no one else can
> either. 

It's impossible? How about:
   const int x = someFuncThatReturnsConst();
?
Your statement is only true if the said variable is static AND has an 
initializer.
(also, to be more accurate, the type in the example should be changed to 
something other than a basic type like int)

-- 
Bruno Medeiros - Software Developer, MSc. in CS/E graduate
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d mailing list