Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi XE4 - Octal constant is working like decimal constant

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!

like image 752
Ivkin Igor Avatar asked Dec 19 '22 15:12

Ivkin Igor


1 Answers

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

like image 170
MBo Avatar answered Dec 24 '22 02:12

MBo