As discussed in Section 5.4, SIDL supports both normal and raw arrays (i.e., r-arrays). Normal SIDL arrays can be used by any supported language; whereas, r-arrays are restricted to numeric types and use in languages such as C, C++, and Fortran. This subsection discusses both within the context of C bindings. More information on the C version of the SIDL array API can be found in Subsection 5.4.
In addition to defining the object structure and associated type for
user-defined interfaces and classes, Babel also defines a corresponding
array structure for normal SIDL arrays. The C mappings for the SIDL base
interface and class are
/** * Symbol "sidl.BaseInterface" (version 0.9.12) * * Every interface in <code>SIDL</code> implicitly inherits * from <code>BaseInterface</code>, which is implemented * by <code>BaseClass</code> below. */ struct sidl_BaseInterface__object; struct sidl_BaseInterface__array; typedef struct sidl_BaseInterface__object* sidl_BaseInterface; /** * Symbol "sidl.BaseClass" (version 0.9.12) * * Every class implicitly inherits from <code>BaseClass</code>. This * class implements the methods in <code>BaseInterface</code>. */ struct sidl_BaseClass__object; struct sidl_BaseClass__array; typedef struct sidl_BaseClass__object* sidl_BaseClass;
Given the package num and class Linsol with the solve
method specified in Subsection 5.4, the corresponding generated
C API is
/** C client-side API for solve method */ void num_Linsol_solve(/* in */ num_Linsol self, /* in rarray[m,n] */ double* A, /* inout rarray[n] */ double* x, /* in */ int32_t m, /* in */ int32_t n, /* out */ sidl_BaseInterface *_ex);
In this example, data for each array is passed as a double pointer with the index parameters being normal in integers. The one catch for C programmers is that A is in column-major order -- not the typical row-major ordering used in C.
Access to the element in row i and column j can be facilitated using RarrayElem2(A,i,j,m). RarrayElem2, defined in sidlArray.h, is a convenience macro -- for C and C++ programmers -- supplied to facilitate accessing r-arrays in column-major order. Access to memory by stride one involves making the first index argument to RarrayElem2, i, the inner loop. Since valid pointers are always required for raw arrays, passing NULL for A, x, or b is not allowed.