Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
January 31, 2004 int[][] | ||||
---|---|---|---|---|
| ||||
Can somebody please explain why this code: int[20][2] whatever; whatever[19][0] = 2; gives this error: test.d(6): array index [19] is outside array bounds [0 .. 2] and this code gives the same error: int[2][20] whatever; whatever[0][19] = 2; test.d(6): array index [19] is outside array bounds [0 .. 2] Im still using v0.77 so was it a bug in this ver or am I doing this wrong? Phill. |
January 31, 2004 Re: int[][] | ||||
---|---|---|---|---|
| ||||
Posted in reply to Phill | and even stranger this compiles and runs: int[2][20] test; test[19][0] = 2; Phill. "Phill" <phill@pacific.net.au> wrote in message news:bvfd9p$2qef$1@digitaldaemon.com... > Can somebody please explain why this code: > > int[20][2] whatever; > whatever[19][0] = 2; > > gives this error: > > test.d(6): array index [19] is outside array bounds [0 .. 2] > > and this code gives the same error: > > int[2][20] whatever; > whatever[0][19] = 2; > > test.d(6): array index [19] is outside array bounds [0 .. 2] > > Im still using v0.77 so was it a bug in this ver or am > I doing this wrong? > > Phill. > > > |
January 31, 2004 Re: int[][] | ||||
---|---|---|---|---|
| ||||
Posted in reply to Phill | Phill wrote: > Can somebody please explain why this code: > > int[20][2] whatever; > whatever[19][0] = 2; > > gives this error: > > test.d(6): array index [19] is outside array bounds [0 .. 2] > > and this code gives the same error: > > int[2][20] whatever; > whatever[0][19] = 2; > > test.d(6): array index [19] is outside array bounds [0 .. 2] > > Im still using v0.77 so was it a bug in this ver or am > I doing this wrong? > > Phill. > > > You might try: int[20][2] whatever; whatever[0][19] = 2; or int whatever[2][20]; whatever[0][19] = 2; It's like this on purpose. I think it's to faciliate porting exotic code from C, but I don't recall any more details. -- Justin http://jcc_7.tripod.com/d/ |
January 31, 2004 Re: int[][] | ||||
---|---|---|---|---|
| ||||
Posted in reply to J C Calvarese | Ok thanks! I like exotic :o)) Phill. "J C Calvarese" <jcc7@cox.net> wrote in message news:bvfeni$2t8u$1@digitaldaemon.com... > Phill wrote: > > > Can somebody please explain why this code: > > > > int[20][2] whatever; > > whatever[19][0] = 2; > > > > gives this error: > > > > test.d(6): array index [19] is outside array bounds [0 .. 2] > > > > and this code gives the same error: > > > > int[2][20] whatever; > > whatever[0][19] = 2; > > > > test.d(6): array index [19] is outside array bounds [0 .. 2] > > > > Im still using v0.77 so was it a bug in this ver or am > > I doing this wrong? > > > > Phill. > > > > > > > > You might try: > > int[20][2] whatever; > whatever[0][19] = 2; > > or > > int whatever[2][20]; > whatever[0][19] = 2; > > > It's like this on purpose. I think it's to faciliate porting exotic code from C, but I don't recall any more details. > > -- > Justin > http://jcc_7.tripod.com/d/ |
February 02, 2004 Re: int[][] | ||||
---|---|---|---|---|
| ||||
Posted in reply to Phill | While it was 31/1/04 5:09 am throughout the UK, Phill sprinkled little black dots on a white screen, and they fell thus: > Can somebody please explain why this code: > > int[20][2] whatever; > whatever[19][0] = 2; > > gives this error: > > test.d(6): array index [19] is outside array bounds [0 .. 2] <snip> So that the syntax is logical. int[20][2] is an array of two int[20]s, not of 20 int[2]s. Declarations then read from right to left, rather than C-style middle to right and then to left, or hopping about as you were thinking of it. Stewart. -- My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment. Please keep replies on the 'group where everyone may benefit. |
February 03, 2004 Re: int[][] | ||||
---|---|---|---|---|
| ||||
Posted in reply to Stewart Gordon | Ok I get the picture, thanks. Its just different than I have been using before. Phill. "Stewart Gordon" <smjg_1998@yahoo.com> wrote in message news:bvlmg9$1268$1@digitaldaemon.com... > While it was 31/1/04 5:09 am throughout the UK, Phill sprinkled little black dots on a white screen, and they fell thus: > > Can somebody please explain why this code: > > > > int[20][2] whatever; > > whatever[19][0] = 2; > > > > gives this error: > > > > test.d(6): array index [19] is outside array bounds [0 .. 2] > <snip> > > So that the syntax is logical. > > int[20][2] is an array of two int[20]s, not of 20 int[2]s. > > Declarations then read from right to left, rather than C-style middle to right and then to left, or hopping about as you were thinking of it. > > Stewart. > > -- > My e-mail is valid but not my primary mailbox, aside from its being the unfortunate victim of intensive mail-bombing at the moment. Please keep replies on the 'group where everyone may benefit. |
Copyright © 1999-2021 by the D Language Foundation