Question

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!

Was it helpful?

Solution

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top