digitalmars.D.learn - 'static' keyword for positional array initialization
- Ali Cehreli (5/5) Aug 11 2009 The 'static' keyword is required by dmd 2.031 for the second of these tw...
- Lars T. Kyllingstad (8/17) Aug 12 2009 I've tried with DMD 2.031, and I can't reproduce this. This works fine
- Ali Cehreli (12/20) Aug 12 2009 Thank you very much for both of your answers. :)
- Lars T. Kyllingstad (5/33) Aug 12 2009 The error message shows that this is definitely a compiler bug. Would
- grauzone (8/32) Aug 12 2009 The error message is a compiler bug, but AFAIK the code above is not
-
Don
(2/24)
Aug 12 2009
I've added this to Bugzilla as bug 3246. With a patch
. - Ali Cehreli (14/23) Aug 12 2009 Thank you for the quick fix! :)
- Don (7/37) Aug 12 2009 'static' means two different things. There, it means 'fixed length'.
The 'static' keyword is required by dmd 2.031 for the second of these two definitions: int[2] static_0 = [ 1, 1 ]; static int[2] static_1 = [ 1:1 ]; Is this inconsistency by design? Should 'static' be required for both or neither? Ali
Aug 11 2009
Ali Cehreli wrote:The 'static' keyword is required by dmd 2.031 for the second of these two definitions: int[2] static_0 = [ 1, 1 ]; static int[2] static_1 = [ 1:1 ]; Is this inconsistency by design? Should 'static' be required for both or neither? AliI've tried with DMD 2.031, and I can't reproduce this. This works fine for me: int[2] static_0 = [ 1, 1 ]: int[2] static_1 = [ 1:1 ]; Where did you put the declarations? I've tried putting them at both module level and in a class, and both times it compiled without problems. -Lars
Aug 12 2009
Lars T. Kyllingstad Wrote:I've tried with DMD 2.031, and I can't reproduce this. This works fine for me: int[2] static_0 = [ 1, 1 ]: int[2] static_1 = [ 1:1 ]; Where did you put the declarations? I've tried putting them at both module level and in a class, and both times it compiled without problems.Thank you very much for both of your answers. :) I hadn't realized that the location of the definitions would make a difference. As you say, both of the lines work for me in the global scope (probably in a class too), but not in main: void main() { int[2] static_0 = [ 1, 1 ]; int[2] static_1 = [ 1:1 ]; } dmd: init.c:431: virtual Expression* ArrayInitializer::toExpression(): Assertion `j < edim' failed. The 'static' keyword on the 1:1 line fixes the problem... I am wondering what the correct syntax is... I am writing a D tutorial, so I think I ought to know. :D If this is a bug, I can leave a temporary note mentioning the bug... :) Ali
Aug 12 2009
Ali Cehreli wrote:Lars T. Kyllingstad Wrote:The error message shows that this is definitely a compiler bug. Would you mind adding it to Bugzilla? http://d.puremagic.com/issues/ -LarsI've tried with DMD 2.031, and I can't reproduce this. This works fine for me: int[2] static_0 = [ 1, 1 ]: int[2] static_1 = [ 1:1 ]; Where did you put the declarations? I've tried putting them at both module level and in a class, and both times it compiled without problems.Thank you very much for both of your answers. :) I hadn't realized that the location of the definitions would make a difference. As you say, both of the lines work for me in the global scope (probably in a class too), but not in main: void main() { int[2] static_0 = [ 1, 1 ]; int[2] static_1 = [ 1:1 ]; } dmd: init.c:431: virtual Expression* ArrayInitializer::toExpression(): Assertion `j < edim' failed. The 'static' keyword on the 1:1 line fixes the problem... I am wondering what the correct syntax is... I am writing a D tutorial, so I think I ought to know. :D If this is a bug, I can leave a temporary note mentioning the bug... :) Ali
Aug 12 2009
Ali Cehreli wrote:Lars T. Kyllingstad Wrote:The error message is a compiler bug, but AFAIK the code above is not valid anyway. The special initializer syntax (apparently called static inittializers) for arrays and structs only works for data that's stored on the data segment. This applies for global variables, static variables, and class member initializers. It simply doesn't work for normal variables, which allocate their storage on the stack.I've tried with DMD 2.031, and I can't reproduce this. This works fine for me: int[2] static_0 = [ 1, 1 ]: int[2] static_1 = [ 1:1 ]; Where did you put the declarations? I've tried putting them at both module level and in a class, and both times it compiled without problems.Thank you very much for both of your answers. :) I hadn't realized that the location of the definitions would make a difference. As you say, both of the lines work for me in the global scope (probably in a class too), but not in main: void main() { int[2] static_0 = [ 1, 1 ]; int[2] static_1 = [ 1:1 ]; } dmd: init.c:431: virtual Expression* ArrayInitializer::toExpression(): Assertion `j < edim' failed. The 'static' keyword on the 1:1 line fixes the problem...
Aug 12 2009
Ali Cehreli wrote:Lars T. Kyllingstad Wrote:I've added this to Bugzilla as bug 3246. With a patch <g>.I've tried with DMD 2.031, and I can't reproduce this. This works fine for me: int[2] static_0 = [ 1, 1 ]: int[2] static_1 = [ 1:1 ]; Where did you put the declarations? I've tried putting them at both module level and in a class, and both times it compiled without problems.Thank you very much for both of your answers. :) I hadn't realized that the location of the definitions would make a difference. As you say, both of the lines work for me in the global scope (probably in a class too), but not in main: void main() { int[2] static_0 = [ 1, 1 ]; int[2] static_1 = [ 1:1 ]; } dmd: init.c:431: virtual Expression* ArrayInitializer::toExpression(): Assertion `j < edim' failed.
Aug 12 2009
Don Wrote:Thank you for the quick fix! :) But I still can't parse the answer that I am looking for. :) The compiler should pass the assertion, ok, but what should itdo after that? a) Reject both b) Accept both c) Accept static_0 but reject static_1 Option c would contradict with the documentattion though: http://digitalmars.com/d/2.0/arrays.html It says: "Static arrays are distinguished by having a length fixed at compile time." Also says: "Static Initialization of Static Arrays: Static initalizations are supplied by a list of array element values enclosed in [ ]. The values can be optionally preceded by an index and a :." Those definitions make me think that both static_0 and static_1 should both be accepted. Thank you, Alivoid main() { int[2] static_0 = [ 1, 1 ]; int[2] static_1 = [ 1:1 ]; } dmd: init.c:431: virtual Expression* ArrayInitializer::toExpression(): Assertion `j < edim' failed.I've added this to Bugzilla as bug 3246. With a patch <g>.
Aug 12 2009
Ali Cehreli wrote:Don Wrote:'static' means two different things. There, it means 'fixed length'. It can also mean 'in the static data segment' which is quite different. This terminology causes a lot of confusion.Thank you for the quick fix! :) But I still can't parse the answer that I am looking for. :) The compiler should pass the assertion, ok, but what should itdo after that? a) Reject both b) Accept both c) Accept static_0 but reject static_1 Option c would contradict with the documentattion though: http://digitalmars.com/d/2.0/arrays.html It says: "Static arrays are distinguished by having a length fixed at compile time."void main() { int[2] static_0 = [ 1, 1 ]; int[2] static_1 = [ 1:1 ]; } dmd: init.c:431: virtual Expression* ArrayInitializer::toExpression(): Assertion `j < edim' failed.I've added this to Bugzilla as bug 3246. With a patch <g>.Also says: "Static Initialization of Static Arrays: Static initalizations are supplied by a list of array element values enclosed in [ ]. The values can be optionally preceded by an index and a :." Those definitions make me think that both static_0 and static_1 should both be accepted.Definitely they should, eventually. But right now, the compiler generates really terrible code for array assignments anyway, so you're not losing much.
Aug 12 2009