FreeBASIC  0.91.0
array_setdesc.c
Go to the documentation of this file.
1 
2 /* descriptor set, for non-dynamic local arrays */
3 
4 #include "fb.h"
5 
7  (
8  FBARRAY *array,
9  void *ptr,
10  size_t element_len,
11  size_t dimensions,
12  ...
13  )
14 {
15  va_list ap;
16  size_t i, elements;
17  ssize_t diff;
18  FBARRAYDIM *dim;
19  ssize_t lbTB[FB_MAXDIMENSIONS];
20  ssize_t ubTB[FB_MAXDIMENSIONS];
21 
22  va_start( ap, dimensions );
23 
24  dim = &array->dimTB[0];
25 
26  for( i = 0; i < dimensions; i++ )
27  {
28  lbTB[i] = va_arg( ap, ssize_t );
29  ubTB[i] = va_arg( ap, ssize_t );
30 
31  dim->elements = (ubTB[i] - lbTB[i]) + 1;
32  dim->lbound = lbTB[i];
33  dim->ubound = ubTB[i];
34  ++dim;
35  }
36 
37  va_end( ap );
38 
39  elements = fb_hArrayCalcElements( dimensions, &lbTB[0], &ubTB[0] );
40  diff = fb_hArrayCalcDiff( dimensions, &lbTB[0], &ubTB[0] ) * element_len;
41 
42  array->ptr = ptr;
43 
44  FB_ARRAY_SETDESC( array, element_len, dimensions, elements * element_len, diff );
45 }
46