August 24, 2001 array intialization - this can't be right | ||||
---|---|---|---|---|
| ||||
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 |
August 25, 2001 Re: array intialization - this can't be right | ||||
---|---|---|---|---|
| ||||
Posted in reply to Angus Graham | 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 > > > |
Copyright © 1999-2021 by the D Language Foundation