Currently lbound/ubound will just crash if the specified dimension is drastically out of range, if it's only off-by-one or similar it can get "lucky" and return an undefined value instead of crashing (that's also sort of documented on the wiki). I think this must definitly be fixed by checking the value and at least returning a default value, i.e. 0, or showing an error. In case lbound/ubound are evaluated at compile-time, an error message can be shown easily, for the run-time case there should ideally be an -exx check, but that's a separate thing to work on, and returning 0 should be good enough when -exx was not used.
There also is one special case, if the value 0 is given as dimension, it is treated as if 1 was given. This was already noticed here. I believe this special case behaviour should be removed because it is useless.
Instead, how about using lbound/ubound( array, 0 ) to access the array's dimension count? It could work like this:
Code: Select all
lbound( array, 0 ) = 1-based index of first dimension = 1 (always)
ubound( array, 0 ) = 1-based index of last dimension = dimension count
Code: Select all
'' Look through all dimensions without knowing how many there are:
for d as integer = lbound( array, 0 ) to ubound( array, 0 )
print "dimension " & d & ":", lbound( array, d ), "to", ubound( array, d )
next
Code: Select all
if( ubound( array, 0 ) = 0 ) then
'' array is empty
end if