www.digitalmars.com         C & C++   DMDScript  

D - [BUG](low) incorrect initializing of arrays not reported

reply Manfred Nowak <svv1999 hotmail.com> writes:
dmd 0.79, WIN98SE

void main(){
  static int[]  bar=[0,,,3];

  printf("%d\n", bar[1]);
}

this compiles and outputs `3'.

So long.
Feb 06 2004
parent J Anderson <REMOVEanderson badmama.com.au> writes:
Manfred Nowak wrote:

dmd 0.79, WIN98SE

void main(){
  static int[]  bar=[0,,,3];

  printf("%d\n", bar[1]);
}

this compiles and outputs `3'.

So long.
  

This is to do with empty comma operators being ignored. If you did void main() { static int[] bar=[0,,,3]; printf("%d\n", bar.length); } you would get 2. The parhaps the code should cause a compilation error (or initialize emptys with the default (ie constructor)). -- -Anderson: http://badmama.com.au/~anderson/
Feb 06 2004