delphi xe android 字节,数组 – Delphi XE字节数组索引

问题是:

Is a wrap expected within the Byte() cast?

让我们将反汇编与溢出检查打开/关闭进行比较.

{$Q+}

Project71.dpr.21: for ptr:= 0 to 10 do Values[Byte(ptr-5)]:= 1;

0041D568 33DB xor ebx,ebx

0041D56A 0FB6C3 movzx eax,bl

0041D56D 83E805 sub eax,$05

0041D570 7105 jno $0041d577

0041D572 E82D8DFEFF call @IntOver

0041D577 0FB6C0 movzx eax,al

0041D57A C704870000803F mov [edi+eax*4],$3f800000

0041D581 43 inc ebx

0041D582 80FB0B cmp bl,$0b

0041D585 75E3 jnz $0041d56a

{$Q-}

Project71.dpr.21: for ptr:= 0 to 10 do Values[Byte(ptr-5)]:= 1;

0041D566 B30B mov bl,$0b

0041D568 B808584200 mov eax,$00425808

0041D56D C7000000803F mov [eax],$3f800000

0041D573 83C004 add eax,$04

0041D576 FECB dec bl

0041D578 75F3 jnz $0041d56d

使用{$Q}包装有效,而使用{$Q-}包装不起作用,并且当设置{$R}时,编译器不会为错误的数组索引生成范围错误.

因此,对我来说结论是:由于范围检查不会为数组索引超出边界生成运行时错误,因此需要进行换行.

这一事实进一步证明了在启用溢出检查时完成换行的事实.

这应该报告为编译器中的错误.

注意:@Rudy在他的回答中提供了一种解决方法.

附录:

以下代码:

for ptr:= 0 to 10 do WriteLn(Byte(ptr-5));

产生:

251

252

253

254

255

0

1

2

3

4

5

对于范围/溢出检查的所有组合.

同样值[Byte(-1)]:= 1;为所有编译器选项的值[255]分配1.

The resulting value is obtained by converting the expression in parentheses. This may involve truncation or extension if the size of the specified type differs from that of the expression. The expression’s sign is always preserved.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值