Recent

Author Topic: Binary literals in Dephi mode  (Read 3233 times)

VisualLab

  • Sr. Member
  • ****
  • Posts: 312
Binary literals in Dephi mode
« on: January 07, 2022, 08:36:23 pm »
Is there a chance that the Free Pascal compiler will allow the use of literals in binary notation in a Delphi compliant compilation mode, ie: {$ mode Delphi}. I mean something like this:

Code: Pascal  [Select][+][-]
  1. ...
  2. {$mode Delphi}
  3. ...
  4. const
  5.   SMyValue = %1011;
  6. var
  7.   A: Integer;
  8. begin
  9.   A := %1001101;
  10. ...

The reason I am asking is because, for some time now, the Delphi compiler has finally accepts literals in binary notation in the source code. This appears to have been introduced in Delphi 10.4 (Sydney). This reference is in the Delphi help system on the Embarcadero website:

https://docwiki.embarcadero.com/RADStudio/Sydney/en/Fundamental_Syntactic_Elements_(Delphi)

in the section: "Binary Literals and Digit Separator").

There are also mentions of this on the website:

https://docwiki.embarcadero.com/RADStudio/Alexandria/en/What%27s_New

in the section: "Binary Literals and Digit Separator" and in the Alister Christie podcast:

https://www.youtube.com/watch?v=MskLyUagI8Y

Such a possibility would allow a set of different constants, classes using generics and declared constants to be placed in one module. I use this notation in the code of my own library supporting embedded devices (RPi, UP Squared). At the same time, the code of classes using generics is clearer and simpler in the variant proposed by Embarcadero (at least for me). In any case, I currently have to split the source code between two separate modules, even though it relates to the same topic/subject.


VisualLab

  • Sr. Member
  • ****
  • Posts: 312
Re: Binary literals in Dephi mode
« Reply #2 on: January 07, 2022, 09:05:05 pm »
A very nice news :-) So it remains patient to wait for Lazarus with a compiler version that supports this possibility.

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1314
    • Lebeau Software
Re: Binary literals in Dephi mode
« Reply #3 on: January 10, 2022, 02:29:15 am »
Is there a chance that the Free Pascal compiler will allow the use of literals in binary notation in a Delphi compliant compilation mode

I wouldn't hold my breath for it, considering {$mode Delphi} doesn't support most of the newer language features introduced after Delphi 7. The only new Delphi language feature added to FPC in recent years is UnicodeString, introduced in Delphi 2009, but that doesn't work in {$mode Delphi}, it requires {$mode DelphiUnicode}/{$modeswitch UnicodeStrings}.

The reason I am asking is because, for some time now, the Delphi compiler has finally accepts literals in binary notation in the source code.

"for some time now" being only 4 months.

This appears to have been introduced in Delphi 10.4 (Sydney).

Actually, it was introduced in Delphi 11.0 Alexandria:

https://docwiki.embarcadero.com/RADStudio/Alexandria/en/What%27s_New#Binary_Literals_and_Digit_Separator

This reference is in the Delphi help system on the Embarcadero website:

https://docwiki.embarcadero.com/RADStudio/Sydney/en/Fundamental_Syntactic_Elements_(Delphi)

The Sydney documentation is wrong.  The feature was not available until Alexandria.

There are also mentions of this ... in the Alister Christie podcast:

https://www.youtube.com/watch?v=MskLyUagI8Y

That video even says Delphi 11.

Such a possibility would allow a set of different constants, classes using generics and declared constants to be placed in one module.

What do you mean?

I use this notation in the code of my own library supporting embedded devices (RPi, UP Squared). At the same time, the code of classes using generics is clearer and simpler in the variant proposed by Embarcadero (at least for me). In any case, I currently have to split the source code between two separate modules, even though it relates to the same topic/subject.

Can you provide an example?
« Last Edit: January 10, 2022, 02:31:15 am by Remy Lebeau »
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1314
    • Lebeau Software
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

PascalDragon

  • Hero Member
  • *****
  • Posts: 5469
  • Compiler Developer
Re: Binary literals in Dephi mode
« Reply #5 on: January 10, 2022, 02:04:33 pm »
I wouldn't hold my breath for it, considering ...

I stand corrected...

Done in last days
https://gitlab.com/freepascal.org/fpc/source/-/commit/25eab57a582a022f3336e052971fd56d9d3cbfd9

Considering that Delphi introduced it because FPC supports it (yes, "other Pascal compilers" was explicitly mentioned and there aren't that many around ;) ) and for us it was a simple if-condition this was essentially a no-brainer. :P

Things like supporting UnicodeString as default string type is a much more different beast, cause even if you use {$mode DelphiUnicode} that won't change that e.g. Classes.TStrings still uses AnsiString.

Thaddy

  • Hero Member
  • *****
  • Posts: 14364
  • Sensorship about opinions does not belong here.
Re: Binary literals in Dephi mode
« Reply #6 on: January 15, 2022, 02:05:59 pm »
I wouldn't hold my breath for it, considering {$mode Delphi} doesn't support most of the newer language features introduced after Delphi 7.
If you mean "most" is two or three, you would be correct.
The Freepascal compiler supports most of the Latest Delphi syntax and misses most notably just anonymous methods and inline vars. The latter will never be implemented, according to devs. The former is being worked on.
That doesn't mean that there are features in the Delphi RTL that are not in the FPC RTL, like TMonitor, but your statement is a bit gross. Also note that Delphi supports less than 25% of the features of FreePascal. O:-)
Note that unimplemented RTL features really partly depend on anonymous methods to become available. And a lot of it is time.. like your remark about the unicode version of the complete rtl. Personally I sometimes add some patches to improve compatibility, many on this forum do.
You may want to use FPC on a more regular basis, that would avoid such statements.
Note I also use Delphi and used to be a betatester (from 1 upto and including 2007, even worked for Borland a couple of specific months. Both FPC and Delphi have their strengths, but a value proposition like yours is way out of line.
« Last Edit: January 15, 2022, 02:26:06 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

 

TinyPortal © 2005-2018