【发布时间】:2011-01-17 20:11:48
【问题描述】:
请帮助我进行回归测试,并确定以下代码在哪些 Delphi 版本中失败。
编辑: 我知道有一个编译器提示;事实上,在我继承的一个项目中发现,不知何故关闭了编译器提示(我看到很多人这样做,因为他们认为编译器提示总是无害的,这个案例表明它不是)。
我仍然想知道这个编译器异常存在于哪些 Delphi 版本中,以用于文档目的。
[DCC Hint] QC90921_SO4717399TestCase.pas(47): H2135 FOR or WHILE loop executes zero times - deleted
在 Delphi XE、2009、2007 和 5 中,它失败并显示以下输出。
我还没有时间研究其他 Delphi 版本。
请帮助我,并回答其他哪些 Delphi 版本也失败了。
Low/High const fail: 0
Low/High hex literal fail: 0
Low/High decimal literal fail: 0
这也是QC 90921的一部分代码:
program Project1;
{$APPTYPE CONSOLE}
uses
SysUtils;
var
CardinalIndex: Cardinal;
CardinalFirst: Cardinal;
CardinalLast: Cardinal;
Count: Int64;
Target: Int64;
begin
try
Target := High(Cardinal);
Inc(Target);
Count := 0;
for CardinalIndex := Low(CardinalIndex) to High(CardinalIndex) do
Inc(Count);
if Target <> Count then
Writeln('Low/High const fail: ', Count);
Count := 0;
for CardinalIndex := 0 to $FFFFFFFF do
Inc(Count);
if Target <> Count then
Writeln('Low/High hex literal fail: ', Count);
Count := 0;
for CardinalIndex := 0 to 4294967295 do
Inc(Count);
if Target <> Count then
Writeln('Low/High decimal literal fail: ', Count);
Count := 0;
CardinalFirst := Low(Cardinal);
CardinalLast := High(Cardinal);
for CardinalIndex := CardinalFirst to CardinalLast do
Inc(Count);
if Target <> Count then
Writeln('Low/High variable fail: ', Count);
Count := 0;
CardinalFirst := 0;
CardinalLast := $FFFFFFFF;
for CardinalIndex := CardinalFirst to CardinalLast do
Inc(Count);
if Target <> Count then
Writeln('hex literal Variable fail: ', Count);
Count := 0;
CardinalFirst := 0;
CardinalLast := 4294967295;
for CardinalIndex := CardinalFirst to CardinalLast do
Inc(Count);
if Target <> Count then
Writeln('decimal literal Variable fail: ', Count);
Write('Press <Enter>');
Readln;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.
编辑: 答案摘要;在这些 Delphi 版本中失败:
- 5
- 6
- 7
- 2006
- 2007
- 2009
- 2010
- XE
--杰罗恩
【问题讨论】:
-
您的问题是您的 for 循环会立即终止,而不是运行 2^32 次迭代?但前提是开始/结束值是编译时常量,而不是变量。
-
@Sertac - 您应该将此链接作为/答案发布。
-
@Deltics - 这有点猜测,因为我没有做过任何测试,但还是回答了。
-
与 Delphi 7 的输出相同,前两个循环被删除(FOR 或 WHILE 循环执行零次 - 已删除)。请参阅 Sertac Akyuz 的回答。
标签: delphi delphi-2009 delphi-2007 delphi-xe