Non compile time evaluation for initializers

Bill Baxter dnewsgroup at billbaxter.com
Fri Oct 26 00:44:35 PDT 2007


Bill Baxter wrote:
> Janice Caron wrote:
>> On 10/25/07, Steven Schveighoffer <schveiguy at yahoo.com> wrote:
>>> Is there a good reason why the compiler does not allow non-CTFE 
>>> initializers
>>> for non-const variables?
>>
>> So you're saying that, in general, if
>>
>>     X x = y;
>>
>> won't compile, then the compiler should rewrite it as
>>
>>     X x;
>>     static this
>>     {
>>         x = y;
>>     }
>>
>> Makes sense to me!
> 
> I think that's only the case for X x being static in the first place.
> So
> 
>   static X x = y;
> 
> is rewritten
> 
>   static X x;
>   static this {
>       x = y;
>   }

Ignore that part.

I think I was thinking about class X x being a class member.
so
class Foo {
    static X x = y;
}
becomes
class Foo {
    static X x;
}
static this {
     Foo.x = y;
}

--bb



More information about the Digitalmars-d mailing list