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

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.

主站蜘蛛池模板: 四平市| 祁门县| 城市| 白城市| 河西区| 临泽县| 丰顺县| 论坛| 华安县| 潞西市| 五莲县| 钟祥市| 武强县| 南岸区| 赤峰市| 桂阳县| 三原县| 阿尔山市| 封丘县| 雅安市| 乌海市| 盖州市| 博罗县| 崇阳县| 无棣县| 泰兴市| 天柱县| 封丘县| 启东市| 镇赉县| 五峰| 时尚| 九龙县| 依安县| 静乐县| 高雄县| 宣汉县| 富阳市| 泾源县| 县级市| 云龙县|