首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >QuickBasic 4.5中不一致的REDIM行为

QuickBasic 4.5中不一致的REDIM行为
EN

Stack Overflow用户
提问于 2022-12-04 12:34:19
回答 1查看 23关注 0票数 1

我正在编写一个玩具QBasic编译器,并对它进行了一些测试。当我试图创建一个向量类型时,我遇到了与REDIM不一致的地方。

以下代码适用于QBasic和QuickBasic 4.5 解释器。但是,当编译为EXE时,它会为第二个REDIM生成“超出范围的子脚本”错误。

代码语言:javascript
复制
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编译器有关。

EN

回答 1

Stack Overflow用户

发布于 2022-12-04 20:10:32

它确实是编译器中的一个bug。

这篇KB文章描述了问题:Q50638:“超出范围的子脚本”,如果在SUB中REDIM长整数数组

代码语言:javascript
复制
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.
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74675645

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档