在德尔福如何检测Int64
的溢出错误?德尔福 - 检测Int64溢出错误
对于整数我们可以这样做:
type
MyInt = Integer; //Int64
function TryMaxTimes10(out Res: MyInt): boolean;
var
a, b: MyInt;
begin
{$Q+}
try
a := High(MyInt);
b := 10;
Res := a * b; //REF1
Result := True;
except
Result := False;
end;
{$Q-}
end;
对于MyInt = Integer
,线REF1给出了一个例外,因此TryMaxTimes10
回报false
。
但是,如果我们将MyInt更改为MyInt = Int64
,那么REF1不会例外,并且TryMaxTimes10
返回true
!
我明白,{$Q+}
帮助没有具体提及Int64
:... {$Q+} state, certain integer arithmetic operations ... are checked for overflow
。
问题:所以我的问题是,我们如何检测Int64的溢出错误?
(我用Delphi 7做同样的事情在Delphi的新版本出现?)
正在进一步调查中似乎有在__llmulo(system.pas)的错误。 – mas 2012-07-05 13:43:39
我在这里找到了一种(有点)解决方法:http://qc.embarcadero.com/wc/qcmain.aspx?d=34049,我可以使用类似的Fastcode来修补__llmulo。问题是,解决方法代码可能包含错误(请参阅QA页面中的进一步注释)。有人有睾丸/工作__llmulo? – mas 2012-07-05 20:21:25