[dmd-beta] dmd 2.064 beta take 2

Михаил Страшун m.strashun at gmail.com
Thu May 16 09:52:30 PDT 2013


On Thu, May 16, 2013 at 1:02 PM, Maxim Fomin <maxim at maxim-fomin.ru> wrote:
>
>
>
> 2013/5/16 Михаил Страшун <m.strashun at gmail.com>
>>
>> Wall of text incoming.
>>
>> First. I'd like to remind to several important properties of D structs:
>>
>> * They have both compile-time initialization and run-time one. First
>> is T.init, second is T(...). Needing both is a perfectly valid need
>> from the programmer, especially with generic code in question.
>
>
> T.init is statically known constant default value of a type and T(..)
> expression when applied to
> the struct can be a struct literal, constructor invocation or an opCall.
>
> Default value (T.init) is same both in compile time and runtime unless you
> deliberatly hack
> generated object file at runtime. But this has nothing to do with
> "compile-time initialization" and "runtime initialization".

You have just said the very same but in different words. What is
important that you need both "const x = ..." syntax to change T.init
and ability to change it in literal/constructor when struct is created
at run-time.

>> * structs always have constructors. So this snippet is wrong:
>> >   struct S
>> >   {
>> >       immutable int c = 123; // This should be static, compiler issues
>> > error
>> >       // No constructor
>> >   }
>> In fact, S has constructor. All structs have constructor with
>> parameter count that matches member field count. And judging only by S
>> definition you can't ever possibly say if "c" will be the same in all
>> S instances or not.
>
>
> No. This S does not have a constructor. Expressions with "parameter count
> that mathces
> member field count" is struct literal and it has nothing to do with implicit
> constructor generation
> or calling any function. Please check things before you type.

Difference does not matter in this context (I apologize for bad
wording though). What I am saying, you can never say that immutable
field value will always stay the same even in absence of explicit
constructors. What you say does not contradict it.


More information about the dmd-beta mailing list