Array init

2009-08-31 Thread bearophile
A question about D1 specs (that may be useful for LDC). In the following code there's anarray of structs S. Is it OK, according to D1 specs, to not initialize the memory of this array if the compiler sees that all fields of S have a void init? struct S { double x = void, y = void; } void main()

Assoc array init

2020-02-03 Thread JN via Digitalmars-d-learn
int[int] a = [5: 7]; void main() { } This fails because apparently [5: 7] is a "non-const expression". How? Why? Yes, I know I can just init in a static this() section, but that feels like a bad workaround.

Re: Array init

2009-09-01 Thread Max Samukha
bearophile wrote: > A question about D1 specs (that may be useful for LDC). > > In the following code there's anarray of structs S. Is it OK, according to > D1 specs, to not initialize the memory of this array if the compiler sees > that all fields of S have a void init? > > struct S { double x

Re: Array init

2009-09-01 Thread Steven Schveighoffer
On Tue, 01 Sep 2009 07:06:25 -0400, Max Samukha wrote: bearophile wrote: A question about D1 specs (that may be useful for LDC). In the following code there's anarray of structs S. Is it OK, according to D1 specs, to not initialize the memory of this array if the compiler sees that al

Re: Array init

2009-09-01 Thread Max Samukha
Steven Schveighoffer wrote: >> That's an interesting question. The compiler does set void-initialized >> member variables to zeros: >> >> struct S { double x = void, y = void; } >> void main() { >> S s; // x and y are initialized to 0 >> } >> >> I think this is a bug. Such members should be le

Re: Array init

2009-09-01 Thread Max Samukha
Don wrote: > > Agreed. (But it's just a performance issue, it's not incorrect to > initialize them to zero). And void initializers are all about performance :) Otherwise, they are useless.

Re: Array init

2009-09-01 Thread bearophile
Max Samukha: > IMO, the initialization code shouldn't be generated for aggregates that have > all members void-initialized, and consequently for arrays of such > aggregates. Thanks to all people that have given me answers and opinions. I have discussed this topic a bit with Tomas Lindquist Olsen

Re: Assoc array init

2020-02-04 Thread Boris Carvajal via Digitalmars-d-learn
On Tuesday, 4 February 2020 at 07:52:05 UTC, JN wrote: int[int] a = [5: 7]; void main() { } This fails because apparently [5: 7] is a "non-const expression". How? Why? Yes, I know I can just init in a static this() section, but that feels like a bad workaround. AFAIK is not implemented.

Re: Assoc array init

2020-02-04 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, February 4, 2020 12:52:05 AM MST JN via Digitalmars-d-learn wrote: > int[int] a = [5: 7]; > > void main() > { > } > > > This fails because apparently [5: 7] is a "non-const expression". > How? Why? > > Yes, I know I can just init in a static this() section, but that > feels like a bad