我正在编写一个玩具QBasic编译器,并对它进行了一些测试。当我试图创建一个向量类型时,我遇到了与REDIM不一致的地方。
以下代码适用于QBasic和QuickBasic 4.5 解释器。但是,当编译为EXE时,它会为第二个REDIM生成“超出范围的子脚本”错误。
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它是否在某个地方被期望和记录,如果是的话,是否有任何可能的解决办法?
UPD:上面的程序在QBX7.1和QB64上工作得很好,所以它可能与QB4.5编译器有关。
发布于 2022-12-04 20:10:32
它确实是编译器中的一个bug。
这篇KB文章描述了问题:Q50638:“超出范围的子脚本”,如果在SUB中REDIM长整数数组。
REDIMing (redimensioning with REDIM) a dynamic long integer array that
was passed to a SUBprogram generates a "Subscript Out Of Range" error
at run time.
Microsoft has confirmed this to be a problem in Microsoft QuickBASIC
Versions 4.00, 4.00b, and 4.50 for MS-DOS and in Microsoft BASIC
Compiler Versions 6.00 and 6.00b for MS-DOS and MS OS/2 (buglist6.00,
buglist6.00b). This problem was corrected in Microsoft BASIC PDS
Version 7.00 (fixlist7.00).
The "Subscript Out Of Range" occurs whether the SUBprogram is compiled
as part of the main program or it is compiled in a separate module.
You can work around this problem by using an array type other than
long integer, or by passing the array through a COMMON SHARED block.https://stackoverflow.com/questions/74675645
复制相似问题