Delphi:我如何使用$ OVERFLOWCHECKS OFF来禁用溢出检查? [英] Delphi: How do i use $OVERFLOWCHECKS OFF to disable overflow checks?

查看:140
本文介绍了Delphi:我如何使用$ OVERFLOWCHECKS OFF来禁用溢出检查?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些代码导致下溢:

i have bit of code that causes an underflow:

var
    t1, t2, delta: DWORD:
begin
   t1 := 0xffffff00;
   t2 := 0x00000037;

   delta := (t2 - t1);

减法本身 产生溢出(下溢),但我不希望Delphi抛出一个 EIntOverflow 异常。所以我尝试通过禁用溢出检查来禁用生成溢出检查代码:

The subtraction itself does generate an overflow (underflow), but i don't want Delphi to throw an EIntOverflow exception. So i try disabling the generation of overflow checking code by disabling overflow checking:

var
    t1, t2, delta: DWORD:
begin
   t1 := 0xffffff00;
   t2 := 0x00000037;

{$OVERFLOWCHECKS OFF}
   delta := (t2 - t1);
{$OVERFLOWCHECKS ON}

即使使用 OVERFLOWCHECKS OFF 选项,它仍然引发异常。而生成的代码仍然包含检查:

Yet even with the OVERFLOWCHECKS OFF option, it still throws an exception. And the generated code still contains the check:

替代文本http:// i43.tinypic.com/intmrl.jpg

提醒您在 $ Q 上的文档:


溢出检查

类型切换

语法 {$ Q +}或{$ Q-}

{$ OVERFLOWCHECKS ON}或{$ OVERFLOWCHECKS OFF}

默认 {$ Q-}

{$ OVERFLOWCHECKS OFF}

范围本地

Type Switch
Syntax {$Q+} or {$Q-}
{$OVERFLOWCHECKS ON} or {$OVERFLOWCHECKS OFF}
Default {$Q-}
{$OVERFLOWCHECKS OFF}
Scope Local

备注

$ Q指令控制
生成溢出检查代码。
在{$ Q +}状态下,某些整数
算术运算(+, - ,*,Abs,
Sqr,Succ,Pred, Inc em> Dec )是
检查溢出。
的代码每个这些整数运算
操作后面跟着额外的
代码,验证结果是
在受支持的范围内。如果
溢出检查失败,则会引发EIntOverflow
异常(或者如果异常处理为
未启用,程序将
终止)。

The $Q directive controls the generation of overflow checking code. In the {$Q+} state, certain integer arithmetic operations (+, -, *, Abs, Sqr, Succ, Pred, Inc, and Dec) are checked for overflow. The code for each of these integer arithmetic operations is followed by additional code that verifies that the result is within the supported range. If an overflow check fails, an EIntOverflow exception is raised (or the program is terminated if exception handling is not enabled).

$ Q开关通常用于
与$ R开关,
启用和禁用生成
范围检查代码。启用溢出
检查会减慢您的程序,
使其更大一些,因此仅使用{$ Q +}
进行调试。

The $Q switch is usually used in conjunction with the $R switch, which enables and disables the generation of range-checking code. Enabling overflow checking slows down your program and makes it somewhat larger, so use {$Q+} only for debugging.

如何使用 $ OVERFLOWCHECKS OFF 禁用生成溢出检查码?

How do i use $OVERFLOWCHECKS OFF to disable the generation of overflow checking code?

梅森的回答工作。修改后的代码是:

Mason's answer worked. The revised code is:

var
    t1, t2, delta: DWORD:
begin
   t1 := 0xffffff00;
   t2 := 0x00000037;

   delta := Subtract(t2, t1);


{$OVERFLOWCHECKS OFF}
function Subtract(const B, A: DWORD): DWORD; //subtract B-A
begin
   {
      Disabling overflow checking does not work at the line level,
      only the routine level. 
      Hence the function to subtract two numbers.
   }
   Result := (B-A);
end;
{$OVERFLOWCHECKS ON}

对于Google抓取工具,备用问题措辞:如何暂时禁用溢出检查Delphi?

For google crawler, alternate question phrasing: How to temporarily disable overflow checking in Delphi?

推荐答案

它不在线级别工作。您需要关闭整个功能。

It doesn't work at the line level. You need to turn it off for the entire function.

这篇关于Delphi:我如何使用$ OVERFLOWCHECKS OFF来禁用溢出检查?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆