initializing a static array
Simon Bürger
simon.buerger at rwth-aachen.de
Tue Oct 10 13:36:56 UTC 2017
I have a static array inside a struct which I would like to be
initialized to all-zero like so
struct Foo(size_t n)
{
double[n] bar = ... all zeroes ...
}
(note that the default-initializer of double is nan, and not zero)
I tried
double[n] bar = 0; // does not compile
double[n] bar = {0}; // neither does this
double[n] bar = [0]; // compiles, but only sets the first
element, ignoring the rest
Is there a good way to set them all to zero? The only way I can
think of is using string-mixins to generate a string such as
"[0,0,0,0]" with exactly n zeroes. But that seems quite an
overkill for such a basic task. I suspect I might be missing
something obvious here...
More information about the Digitalmars-d-learn
mailing list