I was writing a toy QBasic compiler and some tests for it. When I tried to create a vector type, I encountered an inconsistency with REDIM
.
The following code works in both QBasic and QuickBasic 4.5 interpreters. However, it produces 'Subscript out of range' error for the second REDIM
when compiled as EXE.
DECLARE SUB RedimIntArray (arr() AS INTEGER)
DECLARE SUB RedimLongArray (arr() AS LONG)
' $DYNAMIC
DIM xs(2) AS INTEGER
PRINT UBOUND(xs)
RedimIntArray xs()
PRINT UBOUND(xs)
' $DYNAMIC
DIM ys(2) AS LONG
PRINT UBOUND(ys)
RedimLongArray ys()
PRINT UBOUND(ys)
SUB RedimIntArray (arr() AS INTEGER)
REDIM arr(10) AS INTEGER
END SUB
SUB RedimLongArray (arr() AS LONG)
REDIM arr(10) AS LONG
END SUB
Is it something expected and documented somewhere, and if so, are there any possible fixes for this?
UPD: The program above works fine on QBX 7.1 and QB64, so it might be something to do with the QB 4.5 compiler.