www.digitalmars.com         C & C++   DMDScript  

D - [bug] array initializer

reply Lars Ivar Igesund <larsivar igesund.net> writes:
The docs say that this works:

   int [] def = [ 1, 2, 3 ];

This program fails to compile with the error message below:

void main()
{
   int [] def = [ 1, 2, 3 ];
}

array.d(3): variable def is not a static and cannot have static initializer

Either the docs are wrong, or it's a compiler bug.

Lars Ivar Igesund
Apr 16 2004
next sibling parent J Anderson <REMOVEanderson badmama.com.au> writes:
Lars Ivar Igesund wrote:

 The docs say that this works:

   int [] def = [ 1, 2, 3 ];

 This program fails to compile with the error message below:

 void main()
 {
   int [] def = [ 1, 2, 3 ];
 }

 array.d(3): variable def is not a static and cannot have static 
 initializer

 Either the docs are wrong, or it's a compiler bug.

 Lars Ivar Igesund

int [] def = [ 1, 2, 3 ]; void main() { } It would be nice if what u suggest worked though. -- -Anderson: http://badmama.com.au/~anderson/
Apr 16 2004
prev sibling next sibling parent Stewart Gordon <smjg_1998 yahoo.com> writes:
Lars Ivar Igesund wrote:

 The docs say that this works:
 
   int [] def = [ 1, 2, 3 ];

 array.d(3): variable def is not a static and cannot have static initializer

Yes, there seem to be some arbitrary restrictions that aren't in the spec. See D/26695 Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on on the 'group where everyone may benefit.
Apr 16 2004
prev sibling parent Vathix <vathix dprogramming.com> writes:
Lars Ivar Igesund wrote:
 The docs say that this works:
 
   int [] def = [ 1, 2, 3 ];
 
 This program fails to compile with the error message below:
 
 void main()
 {
   int [] def = [ 1, 2, 3 ];
 }
 
 array.d(3): variable def is not a static and cannot have static initializer
 

I think it just hasn't been implemented yet. The workaround is: const int[] def_init = [1, 2, 3]; int[] def = def_init; -- Christopher E. Miller
Apr 16 2004