Final, Const, Invariant

Don Clugston dac at nospam.com.au
Mon Mar 26 03:24:41 PDT 2007


Walter Bright wrote:
> Don Clugston wrote:
>> My code has const everywhere. In fact, I use 'const' about ten times 
>> as often as 'static' or 'class'. And the new scheme does not seem to 
>> have a direct equivalent for it. How can I say, "I want to refer this 
>> literal by a name, but in all other respects I want it to behave 
>> exactly as a literal"? In particular, I do not want storage associated 
>> with it (attempting to take its address is a bug), and it should work 
>> with CTFE.
> 
> Replacing const with final should do the trick.

Will that prevent taking the address, the same way 'const' does now?

There's also this previously discussed case:

void func(int x)
{
   final a = ctfe_func(7);  // will never change, ever.
   final b = non_ctfe_func(8); // won't change during this function call
}

A largely unrelated question, why are existing 'const' items stored in 
the obj file (instead of being discarded immediately after use)? (I'm 
excluding uninitialised class 'const' items set in the constructor, 
which are fundamentally different).



More information about the Digitalmars-d mailing list