Multi-Dimensional Arrays

Array attributes can also be used with multidimensional arrays. However, be careful to ensure that every dimension of the array has a corresponding attribute. For example:

/* IDL file */
[ uuid(20B309B1-015C-101A-B308-02608C4C9B53),
  version(2.0)
]
void arr2d( [in] short        dlsize,
    [in] short                d2len,
    [in,
      size_is( dlsize, ),
      length_is ( , d2len) ] long    array2d[*][30] ) ;
 

The array shown above is a conformant array (of size dlsize) of 30 element arrays (with d2len elements shipped for each).

The string attribute can also be used with multidimensional arrays. The attribute applies to the least-significant dimension such as a conformant array of strings. You can also use multidimensional pointer attributes, but if you do so, the order of the attributes will be reserved because of the right-to-left behavior associated with pointers. For example:

/* IDL file */
[ uuid(20B309B1-015C-101A-B308-02608C4C9B53),
  version(2.0)
]
void arr2d( [in] short        d1len,
    [in] short                d2len,
       [in] size_is(d1len, d2len) ] long  ** ptr2d) ;
 

In the example above, the variable ptr2d is d1len pointers to d2len pointers to long.

Be sure that a multidimensional array is not equivalent to multiple levels of pointers. A multidimensional array is a single, large block of memory and should not be confused with an array of pointers. Also, ANSI C syntax allows only the most significant (leftmost) array dimension to be unspecified in a multidimensional array. Therefore, the following is a valid statement:

long a1[] [20]
 

Compare this to the following invalid statement:

long a1[20] []