Runtime constant definitions

Bill Baxter wbaxter at gmail.com
Fri Sep 12 08:07:05 PDT 2008


On Fri, Sep 12, 2008 at 9:49 PM, Jarrett Billingsley
<jarrett.billingsley at gmail.com> wrote:
> On Fri, Sep 12, 2008 at 4:20 AM, Lars Kyllingstad
> <public at kyllingen.nospamnet> wrote:
>> Frank Benoit wrote:
>>>
>>> I think 'const' should work.
>>
>> It works! Thanks! :)
>>
>> But isn't this the opposite of the intended behaviour? I thought consts were
>> evaluated at compile time, and finals and static this() blocks at run time.
>> At least that's how I've interpreted the D1 specs.
>>
>> -Lars
>>
>
> http://www.digitalmars.com/d/1.0/attribute.html#const
>
> "A const declaration without an initializer must be initialized in a
> constructor (for class fields) or in a static constructor (for static
> class members, or module variable declarations). "
>
> To be honest I'm not sure if the "un-reassignable" property of "final"
> is documented anywhere.  There is a mention in the 1.011 changelog
> that "final for variables now works" but I don't know what "works"
> means.

Sounds like a bug then.  If there's a loophole for const to init in
static this() there should be the same loophole for final vars.
Almost certainly just an oversight.

--bb


More information about the Digitalmars-d-learn mailing list