mb_ix |
![]() ![]() |
C Syntax int* mb_ix( int ix1, int ix2, int ix3, int ix4 )
C++ Syntax int* mb_ix( int ix1 = 0, int ix2 = 0, int ix3 = 0, int ix4 = 0 )
Creates an Index Array that contains the dimensions of an MyBASIC2 array. The pointer to the Index Array points to a static global array that will be reused every time you call this function. To use more than one Index Array at a time, use mb_ix_set instead.
Index Arrays are passed as an argument to mb_get_array_dimensions and mb_get_array_element_ptr functions. An index array is an array of integers with MB_MAX_DIMENSIONS number of elements. You can also use the typedef LPIXARRAY as a pointer to an Index Array. This function is implemented as an inline function instead of an API function.
Note; The indexes are going left to right in function calls where mb_ix_array( nisse, 1, 2, 3, 4 ) is the same as MyBASIC2 statement DIM nisse( 4, 3, 2, 1 )
Example
///////////////////////////////////////////////////////////////////////////// // int _get_array_int( mb_interpreter_t* s, void** l ) { // Parse Parameter. Note that the indices are specified in reverse order // from DIM or array subscripts. result = GET_ARRAY_INT( 1, 2, 3, 4 ) is // the same as indexing an array with the name NILS result = NILS( 4, 3, 2, 1 ) /// BEGIN_PARSE( s, l ) POP_ARRAY( pArr ) POP_INT( ix1 ) OPT_INT( ix2, 0 ) OPT_INT( ix3, 0 ) OPT_INT( ix4, 0 ) END_PARSE
bool_t bResult = mb_check_array_dimensions( pArr, MB_DT_INT, MB_GT( ix1 ), MB_GT( ix2 ), MB_GT( ix3 ), MB_GT( ix4 ) );
if ( !bResult ) { RETURN_ERROR( SE_RN_INDEX_OUT_OF_BOUND ); } endif
// Return the integer pointed to by d1, d2, d3, d4 int* pInt = mb_get_array_element_ptr( pArr, mb_ix( ix1, ix2, ix3, ix4 ) );
RETURN_INT( *pInt ); } endfunc |