在Delphi中禁用溢出检查 [英] Disabling overflow checks in Delphi
问题描述
这是一个后续问题,与我在阅读关于stackoverflow的另一个问题时看到的答案有关.如果我想禁用特定功能的溢出检查(每个
This is a bit of a follow-on question, related to an answer I saw on another question I was reading on stackoverflow. If I wish to disable overflow-checking for a specific function (per this question), will this code cause the overflow-checking to suddenly become enabled after running the function, even if it wasn't previously enabled in compiler options or code?
{$OVERFLOWCHECKS OFF}
// function here
{$OVERFLOWCHECKS ON}
Do I need to combine this with an IFOPT block (akin to this example perhaps?) to return the overflow-checking to the previous state (so as to not accidentally enable overflow checking on non-debug builds)? Or are the two different, and this be sufficient? Bonus: If I do need IFOPT, what would the specific syntax be for disabling overflow checking conditionally?
推荐答案
是的,您发布的代码段将自动启用溢出检查,而不管以前是什么.
Yes, the snippet you posted will automatically enable overflow checking regardless of what it was before.
这应该有效.如果愿意,可以将 {$ Q +}
和 {$ Q-}
替换为 {$ OVERFLOWCHECKS ON}
和分别{$$ OVERFLOWCHECKS OFF}
.
This should work. If you'd prefer, you can replace {$Q+}
and {$Q-}
with {$OVERFLOWCHECKS ON}
and {$OVERFLOWCHECKS OFF}
respectively.
{$IFOPT Q+}
{$DEFINE OVERFLOW_ON}
{$Q-}
{$ELSE}
{$UNDEF OVERFLOW_ON}
{$ENDIF}
//
// Your code here
//
{$IFDEF OVERFLOW_ON}
{$Q+}
{$UNDEF OVERFLOW_ON}
{$ENDIF}
这篇关于在Delphi中禁用溢出检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!