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

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.

主站蜘蛛池模板: 电白县| 崇州市| 连平县| 曲阳县| 龙岩市| 百色市| 米林县| 宜君县| 麦盖提县| 胶南市| 青河县| 怀集县| 东山县| 安顺市| 始兴县| 海伦市| 讷河市| 八宿县| 博兴县| 大庆市| 海南省| 德庆县| 囊谦县| 青河县| 仪征市| 安庆市| 霍州市| 乌海市| 新巴尔虎左旗| 阿图什市| 青阳县| 郸城县| 靖州| 襄垣县| 天柱县| 仁寿县| 绥棱县| 大姚县| 晋宁县| 博客| 重庆市|