www.digitalmars.com         C & C++   DMDScript  

D - array intialization - this can't be right

reply "Angus Graham" <agraham_d agraham.ca> writes:
Looking at http://www.digitalmars.com/d/ctod.html#arrayinit2 :
The following all produce the same result:
    int a[3] = [ 3, 2, 0 ];
    int a[3] = [ 3, 2 ];              // unsupplied initializers are 0, just
like in C
    int a[3] = [ 3:0, 1:3, 2:2 ];
    int a[3] = [ 3:0, 1:3, 2 ];       // if not supplied, the index is the
previous
			              // one plus one.

It looks like initializing in done one based instead of zero based.  Is that
right?
Now I see that http://www.digitalmars.com/d/arrays.html has it being done
zero based:Static Initialization of Static Arrays	int[3] a = [ 1:2, 3 ];		//
a[0] = 0, a[1] = 2, a[2] = 3
That makes me feel better.
Angus Graham
Aug 24 2001
parent "Walter" <walter digitalmars.com> writes:
It's supposed to be 0 based, regardless of bugs in the documentation!

Angus Graham wrote in message <9m65q5$2uu1$1 digitaldaemon.com>...
Looking at http://www.digitalmars.com/d/ctod.html#arrayinit2 :
The following all produce the same result:
    int a[3] = [ 3, 2, 0 ];
    int a[3] = [ 3, 2 ];              // unsupplied initializers are 0,
just
like in C
    int a[3] = [ 3:0, 1:3, 2:2 ];
    int a[3] = [ 3:0, 1:3, 2 ];       // if not supplied, the index is the
previous
               // one plus one.

It looks like initializing in done one based instead of zero based.  Is
that
right?
Now I see that http://www.digitalmars.com/d/arrays.html has it being done
zero based:Static Initialization of Static Arrays int[3] a = [ 1:2, 3 ]; //
a[0] = 0, a[1] = 2, a[2] = 3
That makes me feel better.
Angus Graham
Aug 24 2001