First off, I'm assuming there's not a huge need for this kind of thing.
I'm working on a problem where I need a UBOUND function that operates on single-dimensioned dynamic arrays.
The macro that I came up with won't work with arrays of strings because those are not single-dimensioned arrays.
And I don't need one for strings right now anyway. 😉
My macro seems like it should work on most common single-dimensioned data types. We'll see ...
Below is an easy to follow demonstration for your toolbox.
'===============================================================================================
' BACKGROUND:
'
' BCX does not have a LBOUND function because the true LBOUND of every BCX array is ZERO.
' BCX does have the UBOUND function but it only works on single-dimensioned STATIC arrays
'
' The macro below will return the number of cells in a DYNAMIC single-dimensioned array.
' By simple observation, the internal CreateArr function adds 2 extra cells to the requested
' memory. That is why my macro (below) subtracts 2 from the result.
'
' This specific example was sucessfully tested using Lcc-Win32, Pelles C, MSVC, Mingw, and Clang
'
' Embarcadero C++ reported one too many on all four of the samples. Beware of Dragons ...
'===============================================================================================
MACRO DYN_UBOUND(i, t) = (LONG)(_msize((i))/SIZEOF(t)-2)
TYPE foo
member_1 AS INTEGER
member_2 AS SINGLE
member_3 AS DOUBLE
END TYPE
DIM DYNAMIC AAA [10] AS foo
DIM DYNAMIC BBB [20] AS INTEGER
DIM DYNAMIC CCC [30] AS SINGLE
DIM DYNAMIC DDD [40] AS DOUBLE
PRINT DYN_UBOUND(AAA, foo) ' AAA is the Array Name, the datatype is foo
PRINT DYN_UBOUND(BBB, INTEGER) ' BBB is the Array Name, the datatype is INTEGER
PRINT DYN_UBOUND(CCC, SINGLE) ' CCC is the Array Name, the datatype is SINGLE
PRINT DYN_UBOUND(DDD, DOUBLE) ' DDD is the Array Name, the datatype is DOUBLE
PAUSE
OUTPUT:
10
20
30
40
Press any key to continue . . .