Delphi XE4-八进制常数的工作方式类似于十进制常数 [英] Delphi XE4 - Octal constant is working like decimal constant

查看:99
本文介绍了Delphi XE4-八进制常数的工作方式类似于十进制常数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天,我正在对队友进行代码审查。它是普通的旧版Delphi,版本为XE4。我检测到这样的代码:

Today i was doing code review of my teammate. It's plain old Delp version XE4. I detected the code like this:

cWin_CountryIdsSet: array[0..243] of integer = (499, 688, 040, ...)

这是十进制ID的列表,但其中一个- 040 -看起来像八进制,对不对?我立即告诉他有关该问题的信息,但他回答:不,它的工作方式就像一个小数,请自行检查。他是对的!我写了一个小例子:

It is the list of decimal IDs but one of them - 040 - looks like octal, right? I immediately told him about the problem but he answered: "No, it works like a decimal, look by yourself". And he was right! I wrote small example:

Writeln(080);
if 80 = 080 then Writeln('They are equal');
Writeln(IntToStr(080));

它显示:

80
They are equal
80 

所以表示此Embarcadero的关于整数常量的解释目前不正确。尤其是这句话是错误的:

So it means that this Embarcadero's explanation about integer constants is incorrect at the moment. Especially this sentence is wrong:


所有以零开头的常量都是八进制的。如果八进制常量包含非法数字8或9,则会报告错误。超过037777777777的八进制常量将被截断。

All constants with an initial zero are taken to be octal. If an octal constant contains the illegal digits 8 or 9, an error is reported. Octal constants exceeding 037777777777 are truncated.

使用数字8并没有出现任何错误,编译器忽略了前导0。有人请解释我,谁错了,现在如何在Delphi中使用八进制常量?

I didn't get any error about using the digit 8 and compiler ignored leading 0. Could someone explain me please who is wrong here and how to work with octal constants in Delphi now?

谢谢!

更新:Delphi不支持显式声明八进制常量。因此,这是多语言开发的诅咒,我错误地打扰了我的队友。谢谢您提供所有答案!

Updated: Delphi doesn't support explicit declaration of octal constant. So, it is curse of multi-language development, i disturbed my teammate wrongfully. Thank you for all the answers!

推荐答案

您链接的是 C ++ 参考,而不是 Delphi 参考。 Delphi不支持八进制文字,仅支持十进制和十六进制文字。

What you linked to is a C++ reference, not a Delphi reference. Delphi does not support octal literals, only Decimal and Hex literals.

这篇关于Delphi XE4-八进制常数的工作方式类似于十进制常数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆