문제

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!

도움이 되었습니까?

해결책

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

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top