Recent

Author Topic: thousands separator in constants  (Read 1537 times)

440bx

  • Hero Member
  • *****
  • Posts: 5284
thousands separator in constants
« on: February 16, 2024, 05:46:28 pm »
Hello,

I'm probably getting some programming languages mixed but I was under the impression that some FPC version started supporting "_" as a thousand separator in numeric constants, e.g,
Code: Pascal  [Select][+][-]
  1. const
  2.   SOME_CONSTANT = 100_000;
but that rewarded me with "Error: Syntax error, ";" expected but "identifier _000" found"

The question is: does FPC support the use of "_" as a thousand separator and if it does, what setting must be set to enable its use ?

Thank you for your help.

PS: if FPC doesn't support "_" as a thousands separator, it would be nice if it did ;)

(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v4.0rc3) on Windows 7 SP1 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 16940
  • Ceterum censeo Trump esse delendam
Re: thousands separator in constants
« Reply #1 on: February 16, 2024, 05:52:18 pm »
It is available in fpc trunk/main, but only in trunk/main afaik.
It is not available in fpc 3.2.x
https://wiki.freepascal.org/FPC_New_Features_Trunk#Support_for_Digit_Separator
« Last Edit: February 16, 2024, 05:57:09 pm by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

cdbc

  • Hero Member
  • *****
  • Posts: 2129
    • http://www.cdbc.dk
Re: thousands separator in constants
« Reply #2 on: February 16, 2024, 05:56:43 pm »
Hi
I just tried, it does not compile in:
Code: [Select]
Free Pascal Compiler version 3.3.1-15019-g664f8fc2ba-dirty [2024/01/28] for x86_64
Copyright (c) 1993-2024 by Florian Klaempfl and others
Target OS: Linux for x86-64
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 3.6 up until Jan 2024 from then on it's both above &: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 4.99

Thaddy

  • Hero Member
  • *****
  • Posts: 16940
  • Ceterum censeo Trump esse delendam
Re: thousands separator in constants
« Reply #3 on: February 16, 2024, 05:58:13 pm »
As per my link:
It is enabled by default in the delphi modes.

In other modes it needs
Code: Pascal  [Select][+][-]
  1. {$modeswitch underscoreisseparator }

But still :a recent 3.3.1 main is necessary.
« Last Edit: February 16, 2024, 06:01:39 pm by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

440bx

  • Hero Member
  • *****
  • Posts: 5284
Re: thousands separator in constants
« Reply #4 on: February 16, 2024, 06:04:59 pm »
It is available in fpc trunk/main, but only in trunk/main afaik.
It is not available in fpc 3.2.x
https://wiki.freepascal.org/FPC_New_Features_Trunk#Support_for_Digit_Separator
and unfortunately it seems to require {$mode Delphi}, it doesn't work in non-Delphi mode.

I wonder why the devs limited it to Delphi mode only... seems like it would be a good idea to make it available in all modes (there doesn't seem to be a good reason to limit it to a specific mode.)

Thank you for your help and thank you cdbc too.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v4.0rc3) on Windows 7 SP1 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 16940
  • Ceterum censeo Trump esse delendam
Re: thousands separator in constants
« Reply #5 on: February 16, 2024, 06:25:15 pm »
unfortunately it seems to require {$mode Delphi}, it doesn't work in non-Delphi mode.
No, it requires a mode switch in other modes.
Code: Pascal  [Select][+][-]
  1. {$modeswitch underscoreisseparator }
Personally I hope it stays that way, but I guess that will be not the case in the future.
« Last Edit: February 16, 2024, 06:28:12 pm by Thaddy »
Due to censorship, I changed this to "Nelly the Elephant". Keeps the message clear.

440bx

  • Hero Member
  • *****
  • Posts: 5284
Re: thousands separator in constants
« Reply #6 on: February 16, 2024, 08:31:04 pm »
I'd love to see that modeswitch back ported to v3.2.2
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v4.0rc3) on Windows 7 SP1 64bit.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5965
  • Compiler Developer
Re: thousands separator in constants
« Reply #7 on: February 18, 2024, 01:51:45 pm »
I'd love to see that modeswitch back ported to v3.2.2

3.2.2 is a released version, it will never change.

So the only possibility is 3.2.3 which will become 3.2.4, but in general we don't backport compiler features to the fixes branch.

440bx

  • Hero Member
  • *****
  • Posts: 5284
Re: thousands separator in constants
« Reply #8 on: February 18, 2024, 02:39:23 pm »
3.2.2 is a released version, it will never change.
I meant one of its "offsprings" but you're right, that wording expressed an impossibility (it wouldn't really be version 3.2.2 anymore.)

So the only possibility is 3.2.3 which will become 3.2.4, but in general we don't backport compiler features to the fixes branch.
That's understandable since that isn't a fix. It would be nice though.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v4.0rc3) on Windows 7 SP1 64bit.

 

TinyPortal © 2005-2018