FreeBASIC  0.91.0
array_lbound.c
Go to the documentation of this file.
1 /* lbound function */
2 
3 #include "fb.h"
4 
5 FBCALL ssize_t fb_ArrayLBound( FBARRAY *array, ssize_t dimension )
6 {
7  /* given dimension is 1-based */
8  dimension -= 1;
9 
10  /* out-of-bound dimension? */
11  if( (dimension < 0) || (dimension >= array->dimensions) ) {
12  /*
13  * lbound( a, 0 ) returns the lower bound of the array's dimTB,
14  * always 1. Any other out-of-bound dimension value returns 0.
15  *
16  * Together with ubound returning the dimension count or -1 for
17  * these cases respectively, we can check the dimension count
18  * and detect empty arrays.
19  *
20  * Using lbound=0 and ubound=-1 for empty arrays is good because
21  * it means that lbound > ubound, which is normally invalid,
22  * and lbound staying 0 allows checks such as
23  * @array(lbound(array)) <> NULL
24  * to keep working.
25  */
26  return dimension == -1 ? 1 : 0;
27  }
28 
29  return array->dimTB[dimension].lbound;
30 }