Another compile-time perversion. Or not?

Bruno Medeiros brunodomedeiros+spam at com.gmail
Fri Sep 1 12:20:30 PDT 2006


Walter Bright wrote:
> Don Clugston wrote:
>> Walter Bright wrote:
>>> There's a bit of chicken and egg problem with it - can't tell if it's 
>>> referenced or not until code generation, which is intimately wrapped 
>>> up with object file generation.
>>
>> But isn't it true that a template consisting only of
>> 'const' and 'static if' will *never* result in code generation?
> 
> There can be:
> 
> template Foo(T)
> {
>     static if (...)
>     const T x;
> }
> 
> int* p = &Foo!(int).x;
> 

Yes, because there are two very different meanings for "const" in D : 
there's "compile-time constant", and there's "variable that can only be 
assigned once", for which the keyword 'final' is used in every other 
modern C-like language, which is how it should be done in D as well (or 
with some other keyword).

(Not that that would be required for or even helpful to the compiler to 
be able to differentiate the two meanings of 'const', in order to see 
which templates can be discarded)

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



More information about the Digitalmars-d-announce mailing list