| Thread overview | ||||||
|---|---|---|---|---|---|---|
|
August 20, 2015 cannot initialize static array by static this() | ||||
|---|---|---|---|---|
| ||||
Following code prints "0" using
DMD32 D Compiler v2.068.0
Is this a bug?
import std.stdio;
class Foo {
static int[10] tbl;
static this() {
foreach(ref v; tbl) {
v = 1;
}
}
}
void main() {
writeln(Foo.tbl[0]);
}
regards, aki.
| ||||
August 20, 2015 Re: cannot initialize static array by static this() | ||||
|---|---|---|---|---|
| ||||
Posted in reply to aki | On 2015-08-20 08:33, aki wrote: > Following code prints "0" using > DMD32 D Compiler v2.068.0 > Is this a bug? > > import std.stdio; > class Foo { > static int[10] tbl; > static this() { > foreach(ref v; tbl) { > v = 1; > } > } > } > void main() { > writeln(Foo.tbl[0]); > } Not sure what's going on, but you can do this more easily using array operations: static this () { tbl[] = 1; // assign all elements to 1 } -- /Jacob Carlborg | |||
August 20, 2015 Re: cannot initialize static array by static this() | ||||
|---|---|---|---|---|
| ||||
Posted in reply to aki | On Thursday 20 August 2015 08:33, aki wrote: > Is this a bug? Yes. Please file a bug at <https://issues.dlang.org/>. | |||
August 21, 2015 Re: cannot initialize static array by static this() | ||||
|---|---|---|---|---|
| ||||
Posted in reply to anonymous | On Thursday, 20 August 2015 at 11:58:21 UTC, anonymous wrote: > On Thursday 20 August 2015 08:33, aki wrote: > >> Is this a bug? > > Yes. Please file a bug at <https://issues.dlang.org/>. done. Issue 14944 - cannot initialize static array by static this() https://issues.dlang.org/show_bug.cgi?id=14944 aki. | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply