www.digitalmars.com         C & C++   DMDScript  

D - int[][]

reply "Phill" <phill pacific.net.au> writes:
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.
Jan 30 2004
next sibling parent "Phill" <phill pacific.net.au> writes:
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.

Jan 30 2004
prev sibling next sibling parent reply J C Calvarese <jcc7 cox.net> writes:
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/
Jan 30 2004
parent "Phill" <phill pacific.net.au> writes:
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/

Jan 30 2004
prev sibling parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
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]

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.
Feb 02 2004
parent "Phill" <phill pacific.net.au> writes:
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]

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.

Feb 02 2004