加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

德尔福最大的错误或限制.常数整数值?

发布时间:2020-12-15 04:29:50 所属栏目:大数据 来源:网络整理
导读:参见英文答案 E2099 Overflow in conversion or arithmetic operation1个 const minDriveFreeSpace: Int64 = 1024*1024*1024*99; 和 var minDriveFreeSpace: Int64;begin minDriveFreeSpace := 1024*1024*1024*99; 会发出: [dcc32 Error] DataStoreLocator.
参见英文答案 > E2099 Overflow in conversion or arithmetic operation1个
const
  minDriveFreeSpace: Int64 = 1024*1024*1024*99;

var
  minDriveFreeSpace: Int64;
begin
  minDriveFreeSpace := 1024*1024*1024*99;

会发出:

[dcc32 Error] DataStoreLocator.pas(92): E2099 Overflow in conversion or arithmetic operation

这是Delphi最大的错误还是限制.常数整数值?

解决方法

您需要在右侧将至少一个值强制转换为Int64.例如,这两个在XE6上编译得非常好:
const
  minDriveFreeSpace = Int64(1024) * 1024 * 1024 * 99;

var
  minDriveFreeSpace2: Int64;
begin
  minDriveFreeSpace2 := Int64(1024)*1024*1024*99;

请注意,它可以是任何一个施放的右值.例如,这也同样有效:

const
  minDriveFreeSpace = 1024 * 1024 * 1024 * Int64(99);

这在Delphi language guide中有记录(虽然相当差) – 强调我的:

In general,arithmetic operations on integers return a value of type Integer,which is equivalent to the 32-bit LongInt. Operations return a value of type Int64 only when performed on one or more Int64 operands. Therefore,the following code produces incorrect results:

var
I: Integer;
J: Int64;
... 
I := High(Integer);
J := I + 1;

To get an Int64 return value in this situation,cast I as Int64:

...
J := Int64(I) + 1;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读