[dmd-beta] dmd 2.064 beta take 2

Maxim Fomin maxim at maxim-fomin.ru
Thu May 16 03:02:15 PDT 2013


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".


>
> * 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/dmd-beta/attachments/20130516/9102582d/attachment.html>


More information about the dmd-beta mailing list