mb_get_array_element_ptr |
![]() ![]() |
void* mb_get_array_element_ptr( LPARRAY pArr, LPIXARRAY ix_array )
Returns the pointer to the specified array item. The size of the ix_array must be at least MB_MAX_DIMENSION_COUNT. The array item should be specified with the right-most dimension in lowest index. For example;
OPTION BASE 1 DIM arr(10,5) AS INTEGER
To get the pointer to item arr(2,4) with base 1 you would fill in ix_array as
ix_array[0] = 3 ix_array[1] = 1 ix_array[2] = 0 ix_array[3] = 0
Note that we need to use 0 based offsets as we normally do in C/C++
Example
///////////////////////////////////////////////////////////////////////////// // Return the total sum of all array items // int _array_sum( mb_interpreter_t* s, void** l ) { // Parse Parameter BEGIN_PARSE( s, l ) POP_ARRAY( pArr ) END_PARSE
int ix_array[MB_MAX_DIMENSIONS];
memset( ix_array, 0, sizeof( ix_array ) ); mb_get_array_dimensions( pArr, ix_array );
// Count number of elements int nCount = 0;
for ( int i = 0; i < MB_MAX_DIMENSIONS; i++ ) { nCount += ix_array[i]; }
// Point to the first element memset( ix_array, 0, sizeof( ix_array ) ); float* pFloat = mb_get_array_element_ptr( pArr, ix_array );
// Get the sum of all elements
float fSum = 0;
for ( int i = 0; i < nCount; i++ ) { fSum += *pFloat; }
// Return Count as INTEGER RETURN_REAL( fSum ); }
|