www.digitalmars.com         C & C++   DMDScript  

D - Arrays of arrays question - answer needed quickly ...

reply "Matthew Wilson" <dmd synesis.com.au> writes:


   byte[][]  array1 = new byte[cAllocs][];

    // Allocate all indexes
    for(j = 0; j < cAllocs; ++j)
    {
     array1[j] = new byte[ . . . ];
    }

In D, this does not work. It has to be

   byte[][]  array1 = new byte[][cAllocs];

    // Allocate all indexes
    for(j = 0; j < cAllocs; ++j)
    {
     array1[j] = new byte[ . . . ];
    }

Is this correct? It seems contradictory.

A quick answer by anyone on this would be _greatly_ appreciated. :)

Matthew
Apr 10 2003
parent reply "Walter" <walter digitalmars.com> writes:
"Matthew Wilson" <dmd synesis.com.au> wrote in message
news:b74opb$2u8$2 digitaldaemon.com...


    byte[][]  array1 = new byte[cAllocs][];

     // Allocate all indexes
     for(j = 0; j < cAllocs; ++j)
     {
      array1[j] = new byte[ . . . ];
     }

 In D, this does not work. It has to be

    byte[][]  array1 = new byte[][cAllocs];

     // Allocate all indexes
     for(j = 0; j < cAllocs; ++j)
     {
      array1[j] = new byte[ . . . ];
     }

 Is this correct? It seems contradictory.

 A quick answer by anyone on this would be _greatly_ appreciated. :)
It's correct. Note that the new syntax matches the declaration syntax.
Apr 11 2003
parent "Matthew Wilson" <dmd synesis.com.au> writes:
Thanks

"Walter" <walter digitalmars.com> wrote in message
news:b760fo$sr2$1 digitaldaemon.com...
 "Matthew Wilson" <dmd synesis.com.au> wrote in message
 news:b74opb$2u8$2 digitaldaemon.com...


    byte[][]  array1 = new byte[cAllocs][];

     // Allocate all indexes
     for(j = 0; j < cAllocs; ++j)
     {
      array1[j] = new byte[ . . . ];
     }

 In D, this does not work. It has to be

    byte[][]  array1 = new byte[][cAllocs];

     // Allocate all indexes
     for(j = 0; j < cAllocs; ++j)
     {
      array1[j] = new byte[ . . . ];
     }

 Is this correct? It seems contradictory.

 A quick answer by anyone on this would be _greatly_ appreciated. :)
It's correct. Note that the new syntax matches the declaration syntax.
Apr 11 2003