11-16-2022, 04:28 PM
Perhaps a command can be added for library writers to test for this?
CheckBase% = _OPTIONBASE
Returns 1 if OPTION BASE 1
Returns 0 if OPTION BASE 0
Returns -1 if OPTION BASE was not set
I was just playing around with OPTION BASE and arrays and I think I may have found a solution for library writers.
If I do this:
OPTION BASE 1
DIM a(100)
a(0) = 10
I get an error.
However, if I do this:
OPTION BASE 1
DIM a(-1 to 100)
a(0) = 10
all is well. As long as the first number in an array is a negative value it seems to allow the use of index 0 and 1 no matter what OPTION BASE is set to. So for arrays in libraries always start them at -1 and any setting by the programmer using OPTION BASE seems to be ignored.
Is this normal behavior or a loophole that I've found?
CheckBase% = _OPTIONBASE
Returns 1 if OPTION BASE 1
Returns 0 if OPTION BASE 0
Returns -1 if OPTION BASE was not set
I was just playing around with OPTION BASE and arrays and I think I may have found a solution for library writers.
If I do this:
OPTION BASE 1
DIM a(100)
a(0) = 10
I get an error.
However, if I do this:
OPTION BASE 1
DIM a(-1 to 100)
a(0) = 10
all is well. As long as the first number in an array is a negative value it seems to allow the use of index 0 and 1 no matter what OPTION BASE is set to. So for arrays in libraries always start them at -1 and any setting by the programmer using OPTION BASE seems to be ignored.
Is this normal behavior or a loophole that I've found?