Array init
bearophile
bearophileHUGS at lycos.com
Tue Sep 1 12:50:24 PDT 2009
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, LDC may be improved a bit.
Regarding test code for present and future D1 compilers I written this:
version (Tango)
import tango.stdc.stdlib: atof;
else
import std.c.stdlib: atof;
version (V1)
void main() {
struct S { double x, y; }
S s;
s.x = atof("10.0");
s.y = atof("20.0");
}
version (V2)
void main() {
struct S { double x, y; }
S s = void;
s.x = atof("10.0");
s.y = atof("20.0");
}
version (V3)
void main() {
struct S { double x, y; }
auto s = S(atof("10.0"), atof("20.0"));
}
version (V4)
void main() {
struct S { double x = void, y = void; }
S s;
s.x = atof("10.0");
s.y = atof("20.0");
}
version (V5)
void main() {
struct S { double x = void, y = void; }
S s = void;
s.x = atof("10.0");
s.y = atof("20.0");
}
version (V6)
void main() {
struct S { double x = void, y = void; }
auto s = S(atof("10.0"), atof("20.0"));
}
I think that in theory a good D compiler has to produce the same optimal code in all those six cases (in some cases removing some double initializations too) :-)
I'll show this code to Lindquist in future.
Bye,
bearophile
More information about the Digitalmars-d-learn
mailing list