官术网_书友最值得收藏!

Overflow checking

The Overflow checking option regulates whether the compiler checks if certain arithmetic operations (+, -, *, Abs, Sqr, Inc, Dec, Succ, and Pred) produce a number that is too large or too small to fit into the data type. You can use compiler options, {$OVERFLOWCHECKS ON} and {$OVERFLOWCHECKS OFF} (or short forms {$Q+} and {$Q-}), to turn this option on and off in a specific part of a program.

For example, the following program will silently increment $FFFFFFFF to 0 in the first Inc statement but will raise EIntOverflow exception in the second Inc statement:


procedure TfrmCompilerOptions.btnOverflowErrorClick(Sender: TObject);
var
i: cardinal;
begin
{$Q-}
i := $FFFFFFFF;
// Without overflow checks, Inc will work and i will be 0
Inc(i);

{$Q+}
i := $FFFFFFFF;
// With overflow checks, Inc will raise an exception
Inc(i);
end;

Enabling overflow checking doesn't make a big change in the program speed, so you can freely use it whenever it is needed. I would suggest turning it on at least in debug configuration as that will help with finding errors in the code.

主站蜘蛛池模板: 永兴县| 康定县| 奉新县| 牟定县| 彭山县| 南岸区| 金溪县| 贺兰县| 仪陇县| 东城区| 万年县| 偏关县| 炉霍县| 阿巴嘎旗| 昭觉县| 辽中县| 高尔夫| 德庆县| 临洮县| 漠河县| 大新县| 铜梁县| 泸水县| 屯门区| 石楼县| 林甸县| 浑源县| 长治市| 从江县| 忻城县| 肥西县| 太白县| 台江县| 永州市| 朝阳市| 灵石县| 靖州| 黄骅市| 南开区| 巴里| 思南县|