Thread overview
[bug] array initializer
Apr 16, 2004
Lars Ivar Igesund
Apr 16, 2004
J Anderson
Apr 16, 2004
Stewart Gordon
Apr 16, 2004
Vathix
April 16, 2004
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

April 16, 2004
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
>
This works, outside the main scope and the error message explains that.

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

void main()
{
}

It would be nice if what u suggest worked though.

-- 
-Anderson: http://badmama.com.au/~anderson/
April 16, 2004
Lars Ivar Igesund wrote:

> The docs say that this works:
> 
>   int [] def = [ 1, 2, 3 ];
<snip>
> array.d(3): variable def is not a static and cannot have static initializer
<snip>

Yes, there seem to be some arbitrary restrictions that aren't in the spec.  See
http://www.digitalmars.com/drn-bin/wwwnews?D/26695

Stewart.

-- 
My e-mail is valid but not my primary mailbox.  Please keep replies on on the 'group where everyone may benefit.
April 16, 2004
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