Delphi XE4 - Octal constant is working like decimal constant

亡梦爱人 提交于 2019-12-10 17:11:21

问题


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

cWin_CountryIdsSet: array[0..243] of integer = (499, 688, 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));

It displays:

80
They are equal
80 

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

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.

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?

Thank you by advance!

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!


回答1:


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




回答2:


Delphi literals can be decimal or hexadecimal. There is no support for any other representation.

The documentation you refer to is for C++ rather than Delphi.



来源:https://stackoverflow.com/questions/23214528/delphi-xe4-octal-constant-is-working-like-decimal-constant

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!