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()
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.
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
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
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
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.
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
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.
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