Forum > General

thousands separator in constants

(1/2) > >>

440bx:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---const  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 ;)

Thaddy:
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

cdbc:
Hi
I just tried, it does not compile in:
--- Code: ---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

--- End code ---
Regards Benny

Thaddy:
As per my link:
It is enabled by default in the delphi modes.

In other modes it needs
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{$modeswitch underscoreisseparator }
But still :a recent 3.3.1 main is necessary.

440bx:

--- Quote from: Thaddy 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

--- End quote ---
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.

Navigation

[0] Message Index

[#] Next page

Go to full version