DMD 1.025 and 2.009 releases

Bill Baxter dnewsgroup at billbaxter.com
Tue Jan 1 21:51:00 PST 2008


Walter Bright wrote:
> Jarrett Billingsley wrote:
>> "Walter Bright" <newshound1 at digitalmars.com> wrote in message 
>> news:flebgf$1pmb$1 at digitalmars.com...
>>
>>> C cx;
>>> if (someCondition)
>>> cx = new C(1);
>>> else
>>> cx = new C(2);
>>> const(C) c = cx;
>>>> ... 
>  Note that this isn't any different from what you'd write for a const int:
> 
>     int ix;
>     if (someCondition)
>     ix = 1;
>     else
>     ix = 2;
>     const(int) i = ix;
> 
> or const of any type.

It's also the same sort of rigmarole you have to go through to 
conditionally initialize a reference in C++ since they cannot be rebound 
except at initialization.  C++ programmers manage to get by with that.

But that still doesn't mean it's the ideal way to do such 
initializations.  In particular it looks pretty inefficient if we're 
talking about a BigStruct instead of an int. (I'd probably just switch 
to using a const pointer to refer to the BigStruct under the current rules.)

At any rate, the lack of this capability doesn't seem a big enough 
problem to justify scrapping the new const.  Or even to try "fixing" it 
with new syntax so soon before we've had the chance to get used to the 
new system.  If the above does turn out to be a big deal in practice, 
perhaps some new initializer syntax could be added to make that sort of 
thing easier, but it doesn't look like a deal-breaker either way.


--bb



More information about the Digitalmars-d-announce mailing list