Multiple Dynamic Array

efgee efgee2003 at yahoo.com
Mon Dec 25 16:57:00 PST 2006


Hi,
as a newbie I have some difficulties with creating and working with multiple
dynamic arrays.

Here is a multiple static array which seems to work fine:
(please tell me if there is anything that can be done better...)

multiple static array test code:

int main (char [] [] args)  {
  static int[64][64][64] A;
  static char[64][64][64] B;
  static int i,j,k,n,x;
  static char c;

  for(n = 1; n <= 100; n ++)
  {
    for(i = 0; i <= 63; i ++)
    {
      for(j = 0; j <= 63; j ++)
      {
        for(k = 0; k <= 63; k++)
        {

          A[i][j][k] = 100; //numeric array write

          x = A[i][j][k];   //numeric array read

          B[i][j][k] = 'A'; //string array write

          c = B[i][j][k];   //string array read

        }
      }
    }
  }

  return 0 ;
}

Here now a dynamic array.
There must be something missing, because it compiles but there is a
ArrayBoundsError on runtime.

multiple dynamic array test code:

int main (char [] [] args)  {
  int i,j,k,n,x;
  int[][][] A;
  char[][][] B;
  char c;

  for(n = 1; n <= 100; n ++)
  {
    for(i = 0; i <= 63; i ++)
    {
      for(j = 0; j <= 63; j ++)
      {
        for(k = 0; k <= 63; k++)
        {

          A[i][j][k] = 100; //numeric array write

          x = A[i][j][k];   //numeric array read

          B[i][j][k] = 'A'; //string array write

          c = B[i][j][k];   //string array read

        }
      }
    }
  }

  return 0 ;
}

Any help is truly appreciated.

Tried to compile it with GDC 0.2 and DMD 0.178


efgee

BTW: Looked for documents for that but all I found was some very simple
example code that didn't explain anything serious.
Is there good documentation for newbies?


More information about the Digitalmars-d-learn mailing list