Recent

Author Topic: FPC 3.2.2 - maximum Length of Identifiers ?  (Read 691 times)

paule32

  • Sr. Member
  • ****
  • Posts: 437
FPC 3.2.2 - maximum Length of Identifiers ?
« on: April 23, 2025, 06:07:14 pm »
Hello,
what is the maximum Length of a Identifier like:

TClass_myForm_1_myForm_2_myForm_A_mnyForm_A_1_ = class(TForm) ... end;

?
MS-IIS - Internet Information Server, Apache, PHP/HTML/CSS, MinGW-32/64 MSys2 GNU C/C++ 13 (-stdc++20), FPC 3.2.2
A Friend in need, is a Friend indeed.

Fibonacci

  • Hero Member
  • *****
  • Posts: 702
  • Internal Error Hunter
Re: FPC 3.2.2 - maximum Length of Identifiers ?
« Reply #1 on: April 23, 2025, 06:13:56 pm »
Code: Pascal  [Select][+][-]
  1. project1.lpr(5,3) Error: Constant strings cannot be longer than 255 chars

paule32

  • Sr. Member
  • ****
  • Posts: 437
Re: FPC 3.2.2 - maximum Length of Identifiers ?
« Reply #2 on: April 23, 2025, 06:18:58 pm »
Hi fibonacci,

Thanks for reply - but this are no good news for me.
I working on a Compiler that supports nested classes.
Currently it converts from one DSL to FPC.

Are Hashes allowed for Class Names ?

like:  T12abc000111_aaa312
???

this will be going into funny way - I see it come ...
MS-IIS - Internet Information Server, Apache, PHP/HTML/CSS, MinGW-32/64 MSys2 GNU C/C++ 13 (-stdc++20), FPC 3.2.2
A Friend in need, is a Friend indeed.

Fibonacci

  • Hero Member
  • *****
  • Posts: 702
  • Internal Error Hunter
Re: FPC 3.2.2 - maximum Length of Identifiers ?
« Reply #3 on: April 23, 2025, 06:33:10 pm »
You can create shorter named classes and a map with longer names. Im not sure what exactly do you want to achieve ;D

Code: Pascal  [Select][+][-]
  1. type
  2.   short_name_for_class = class
  3.     procedure testproc;
  4.   end;
  5.  
  6.   classmapentry = record
  7.     name: string;
  8.     c: tclass;
  9.   end;
  10.  
  11. const
  12.   classes: array[0..0] of classmapentry = (
  13.     (name: 'long_name_for_class_long_name_for_class_long_name_for_class_long_name_for_class'; c: short_name_for_class)
  14.   );
  15.  
  16. procedure short_name_for_class.testproc;
  17. begin
  18.   writeln('testproc called');
  19. end;
  20.  
  21. function getclass(classname: string; out c: tclass): boolean;
  22. var
  23.   i: integer;
  24. begin
  25.   result := false;
  26.   for i := 0 to high(classes) do
  27.     if classes[i].name = classname then begin
  28.       c := classes[i].c;
  29.       exit(true);
  30.     end;
  31. end;
  32.  
  33. var
  34.   myclass: tclass;
  35.  
  36. begin
  37.   if getclass('long_name_for_class_long_name_for_class_long_name_for_class_long_name_for_class', myclass) then begin
  38.     short_name_for_class(myclass).testproc;
  39.   end;
  40.  
  41.   readln;
  42. end.

AFAIK, RTTI in FPC is not at the level you could find a class by its string representation. If it were you could in fact keep the name of the classes as hashes and find them by hashing a string with the class name. But for now, you can use something like above.
« Last Edit: April 23, 2025, 06:37:39 pm by Fibonacci »

paule32

  • Sr. Member
  • ****
  • Posts: 437
Re: FPC 3.2.2 - maximum Length of Identifiers ?
« Reply #4 on: April 23, 2025, 08:07:19 pm »
Thanks fibo.

Currently I work in Hybride Way:
DSL (Source Code) => C++ (Compiler EXE) => FPC (Source Code) => EXE (Compiled x86_64)
MS-IIS - Internet Information Server, Apache, PHP/HTML/CSS, MinGW-32/64 MSys2 GNU C/C++ 13 (-stdc++20), FPC 3.2.2
A Friend in need, is a Friend indeed.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5959
  • Compiler Developer
Re: FPC 3.2.2 - maximum Length of Identifiers ?
« Reply #5 on: April 23, 2025, 08:44:23 pm »
Are Hashes allowed for Class Names ?

like:  T12abc000111_aaa312
???

As long as an identifier starts with a letter from A-Z (upper- or lowercase) or an underscore and further contains either these or numbers it's a valid Pascal identifier.

paule32

  • Sr. Member
  • ****
  • Posts: 437
Re: FPC 3.2.2 - maximum Length of Identifiers ?
« Reply #6 on: April 23, 2025, 11:09:57 pm »
starting with this Code:

Code: Text  [Select][+][-]
  1. parameter bModal
  2.  
  3. class myForm_1 of Form
  4.  
  5.     class myForm_2 of Form
  6.    
  7.         class myForm_A of Form
  8.        
  9.             class mnyForm_A_1 of Form
  10.             classend
  11.            
  12.         classend
  13.        
  14.         class myForm_B of Form
  15.         classend
  16.        
  17.         class myForm_C of Form
  18.        
  19.             class myForm_C2 of Form
  20.             classend
  21.         classend
  22.     classend
  23.    
  24.     class myForm_2B of Form
  25.     classend
  26. classend
  27.  
I get this followed Code below.
This will then result into a 200 KBytes .ppu File
This will then result into a 100 KBytes .o     File

Code: Pascal  [Select][+][-]
  1. {$mode delphi}
  2. UNIT test;
  3.  
  4. INTERFACE
  5.  
  6. USES
  7.   Interfaces, SysUtils, Classes, Forms, Dialogs;
  8.  
  9. TYPE
  10.   TParamScope = (
  11.     PS_UNKNOWN   = 0,
  12.     PS_LOCAL     = 1,
  13.     PS_GLOBAL    = 2,
  14.     PS_PRIVATE   = 3,
  15.     PS_PROTECTED = 4
  16.   );
  17.   TParamType = (
  18.     PT_UNKNOWN = 0,
  19.     PT_NUMERIC = 1,
  20.     PT_STRING  = 2,
  21.     PT_OBJECT  = 3  );
  22.  
  23. TYPE
  24.   TDBParameterClass = CLASS(TObject)
  25.   public
  26.     pName  : String      ;
  27.     pScope : TParamScope ;
  28.     pType  : TParamType  ;
  29.     pSize  : Integer     ;
  30.     pData  : PChar       ;
  31.   END;
  32.  
  33. TYPE
  34.   TDBClass_06200f92_7181_4db7_8e79_9d5cee2d6891 = CLASS(TForm)
  35.   PRIVATE
  36.     FParameter: ARRAY [0..1] OF TDBParameterClass;
  37.   PUBLIC
  38.     PROCEDURE Init;
  39.     PROCEDURE DeInit;
  40.   END;
  41.  
  42. TYPE
  43.   TDBClass_57b5bbea_4f3e_40f3_9c06_59204ddaa18f = CLASS(TForm)
  44.   PRIVATE
  45.     FParameter: ARRAY [0..1] OF TDBParameterClass;
  46.   PUBLIC
  47.     PROCEDURE Init;
  48.     PROCEDURE DeInit;
  49.   END;
  50.  
  51. TYPE
  52.   TDBClass_6e546657_cf75_402f_a9a7_2a2df502d1fe = CLASS(TForm)
  53.   PRIVATE
  54.     FParameter: ARRAY [0..1] OF TDBParameterClass;
  55.   PUBLIC
  56.     PROCEDURE Init;
  57.     PROCEDURE DeInit;
  58.   END;
  59.  
  60. TYPE
  61.   TDBClass_b100651b_44eb_475c_a0fc_c6700b95d0ce = CLASS(TForm)
  62.   PRIVATE
  63.     FParameter: ARRAY [0..1] OF TDBParameterClass;
  64.   PUBLIC
  65.     PROCEDURE Init;
  66.     PROCEDURE DeInit;
  67.   END;
  68.  
  69. TYPE
  70.   TDBClass_b8f06298_ed28_4a53_80df_f6d31d626022 = CLASS(TForm)
  71.   PRIVATE
  72.     FParameter: ARRAY [0..1] OF TDBParameterClass;
  73.   PUBLIC
  74.     PROCEDURE Init;
  75.     PROCEDURE DeInit;
  76.   END;
  77.  
  78. TYPE
  79.   TDBClass_df4d5daf_d635_4550_97e6_f7b474cb3f7a = CLASS(TForm)
  80.   PRIVATE
  81.     FParameter: ARRAY [0..1] OF TDBParameterClass;
  82.   PUBLIC
  83.     PROCEDURE Init;
  84.     PROCEDURE DeInit;
  85.   END;
  86.  
  87. TYPE
  88.   TDBClass_e464d03c_8324_4b1a_a01a_f4ffeba5388c = CLASS(TForm)
  89.   PRIVATE
  90.     FParameter: ARRAY [0..1] OF TDBParameterClass;
  91.   PUBLIC
  92.     PROCEDURE Init;
  93.     PROCEDURE DeInit;
  94.   END;
  95.  
  96. TYPE
  97.   TDBClass_f74fe285_c96d_4948_b31f_e35524b55630 = CLASS(TForm)
  98.   PRIVATE
  99.     FParameter: ARRAY [0..1] OF TDBParameterClass;
  100.   PUBLIC
  101.     PROCEDURE Init;
  102.     PROCEDURE DeInit;
  103.   END;
  104.  
  105.  
  106. IMPLEMENTATION
  107.  
  108. PROCEDURE TDBClass_06200f92_7181_4db7_8e79_9d5cee2d6891.Init;
  109. BEGIN
  110.   FParameter[0] := TDBParameterClass.Create;
  111.   FParameter[0].pName  := 'bModal';
  112.   FParameter[0].pScope := TParamScope(PS_GLOBAL);
  113.   FParameter[0].pType  := TParamType(PT_UNKNOWN);
  114. END;
  115.  
  116. PROCEDURE TDBClass_06200f92_7181_4db7_8e79_9d5cee2d6891.DeInit;
  117. VAR
  118.   IDX : Integer;
  119. BEGIN
  120.   FOR IDX := HIGH(FParameter) DOWNTO LOW(FParameter) DO
  121.   BEGIN
  122.     FParameter[IDX].Free;
  123.     FParameter[IDX] := NIL;
  124.   END;
  125. END;
  126.  
  127. PROCEDURE TDBClass_57b5bbea_4f3e_40f3_9c06_59204ddaa18f.Init;
  128. BEGIN
  129.   FParameter[0] := TDBParameterClass.Create;
  130.   FParameter[0].pName  := 'bModal';
  131.   FParameter[0].pScope := TParamScope(PS_GLOBAL);
  132.   FParameter[0].pType  := TParamType(PT_UNKNOWN);
  133. END;
  134.  
  135. PROCEDURE TDBClass_57b5bbea_4f3e_40f3_9c06_59204ddaa18f.DeInit;
  136. VAR
  137.   IDX : Integer;
  138. BEGIN
  139.   FOR IDX := HIGH(FParameter) DOWNTO LOW(FParameter) DO
  140.   BEGIN
  141.     FParameter[IDX].Free;
  142.     FParameter[IDX] := NIL;
  143.   END;
  144. END;
  145.  
  146. PROCEDURE TDBClass_6e546657_cf75_402f_a9a7_2a2df502d1fe.Init;
  147. BEGIN
  148.   FParameter[0] := TDBParameterClass.Create;
  149.   FParameter[0].pName  := 'bModal';
  150.   FParameter[0].pScope := TParamScope(PS_GLOBAL);
  151.   FParameter[0].pType  := TParamType(PT_UNKNOWN);
  152. END;
  153.  
  154. PROCEDURE TDBClass_6e546657_cf75_402f_a9a7_2a2df502d1fe.DeInit;
  155. VAR
  156.   IDX : Integer;
  157. BEGIN
  158.   FOR IDX := HIGH(FParameter) DOWNTO LOW(FParameter) DO
  159.   BEGIN
  160.     FParameter[IDX].Free;
  161.     FParameter[IDX] := NIL;
  162.   END;
  163. END;
  164.  
  165. PROCEDURE TDBClass_b100651b_44eb_475c_a0fc_c6700b95d0ce.Init;
  166. BEGIN
  167.   FParameter[0] := TDBParameterClass.Create;
  168.   FParameter[0].pName  := 'bModal';
  169.   FParameter[0].pScope := TParamScope(PS_GLOBAL);
  170.   FParameter[0].pType  := TParamType(PT_UNKNOWN);
  171. END;
  172.  
  173. PROCEDURE TDBClass_b100651b_44eb_475c_a0fc_c6700b95d0ce.DeInit;
  174. VAR
  175.   IDX : Integer;
  176. BEGIN
  177.   FOR IDX := HIGH(FParameter) DOWNTO LOW(FParameter) DO
  178.   BEGIN
  179.     FParameter[IDX].Free;
  180.     FParameter[IDX] := NIL;
  181.   END;
  182. END;
  183.  
  184. PROCEDURE TDBClass_b8f06298_ed28_4a53_80df_f6d31d626022.Init;
  185. BEGIN
  186.   FParameter[0] := TDBParameterClass.Create;
  187.   FParameter[0].pName  := 'bModal';
  188.   FParameter[0].pScope := TParamScope(PS_GLOBAL);
  189.   FParameter[0].pType  := TParamType(PT_UNKNOWN);
  190. END;
  191.  
  192. PROCEDURE TDBClass_b8f06298_ed28_4a53_80df_f6d31d626022.DeInit;
  193. VAR
  194.   IDX : Integer;
  195. BEGIN
  196.   FOR IDX := HIGH(FParameter) DOWNTO LOW(FParameter) DO
  197.   BEGIN
  198.     FParameter[IDX].Free;
  199.     FParameter[IDX] := NIL;
  200.   END;
  201. END;
  202.  
  203. PROCEDURE TDBClass_df4d5daf_d635_4550_97e6_f7b474cb3f7a.Init;
  204. BEGIN
  205.   FParameter[0] := TDBParameterClass.Create;
  206.   FParameter[0].pName  := 'bModal';
  207.   FParameter[0].pScope := TParamScope(PS_GLOBAL);
  208.   FParameter[0].pType  := TParamType(PT_UNKNOWN);
  209. END;
  210.  
  211. PROCEDURE TDBClass_df4d5daf_d635_4550_97e6_f7b474cb3f7a.DeInit;
  212. VAR
  213.   IDX : Integer;
  214. BEGIN
  215.   FOR IDX := HIGH(FParameter) DOWNTO LOW(FParameter) DO
  216.   BEGIN
  217.     FParameter[IDX].Free;
  218.     FParameter[IDX] := NIL;
  219.   END;
  220. END;
  221.  
  222. PROCEDURE TDBClass_e464d03c_8324_4b1a_a01a_f4ffeba5388c.Init;
  223. BEGIN
  224.   FParameter[0] := TDBParameterClass.Create;
  225.   FParameter[0].pName  := 'bModal';
  226.   FParameter[0].pScope := TParamScope(PS_GLOBAL);
  227.   FParameter[0].pType  := TParamType(PT_UNKNOWN);
  228. END;
  229.  
  230. PROCEDURE TDBClass_e464d03c_8324_4b1a_a01a_f4ffeba5388c.DeInit;
  231. VAR
  232.   IDX : Integer;
  233. BEGIN
  234.   FOR IDX := HIGH(FParameter) DOWNTO LOW(FParameter) DO
  235.   BEGIN
  236.     FParameter[IDX].Free;
  237.     FParameter[IDX] := NIL;
  238.   END;
  239. END;
  240.  
  241. PROCEDURE TDBClass_f74fe285_c96d_4948_b31f_e35524b55630.Init;
  242. BEGIN
  243.   FParameter[0] := TDBParameterClass.Create;
  244.   FParameter[0].pName  := 'bModal';
  245.   FParameter[0].pScope := TParamScope(PS_GLOBAL);
  246.   FParameter[0].pType  := TParamType(PT_UNKNOWN);
  247. END;
  248.  
  249. PROCEDURE TDBClass_f74fe285_c96d_4948_b31f_e35524b55630.DeInit;
  250. VAR
  251.   IDX : Integer;
  252. BEGIN
  253.   FOR IDX := HIGH(FParameter) DOWNTO LOW(FParameter) DO
  254.   BEGIN
  255.     FParameter[IDX].Free;
  256.     FParameter[IDX] := NIL;
  257.   END;
  258. END;
  259.  
  260. END.

This is not optimized. yet
MS-IIS - Internet Information Server, Apache, PHP/HTML/CSS, MinGW-32/64 MSys2 GNU C/C++ 13 (-stdc++20), FPC 3.2.2
A Friend in need, is a Friend indeed.

Ozz_Nixon

  • Full Member
  • ***
  • Posts: 121
    • http://www.modernpascal.com/
Re: FPC 3.2.2 - maximum Length of Identifiers ?
« Reply #7 on: April 24, 2025, 08:14:58 am »
Hello,
what is the maximum Length of a Identifier like:

TClass_myForm_1_myForm_2_myForm_A_mnyForm_A_1_ = class(TForm) ... end;

?


Free Pascal supports up to 127 characters for an Identifier.
C99 = 32 characters.
TP7 = 63 characters.
DCC32 = E2056 String literals may have at most 255.


Ozz  :-X
---
Want to kick the tires to a Free Pascal like script engine? http://www.ModernPascal.com/

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12181
  • FPC developer.
Re: FPC 3.2.2 - maximum Length of Identifiers ?
« Reply #8 on: April 24, 2025, 08:44:43 am »
Note that the backend of linkers might have other limits.

440bx

  • Hero Member
  • *****
  • Posts: 5264
Re: FPC 3.2.2 - maximum Length of Identifiers ?
« Reply #9 on: April 24, 2025, 09:05:03 am »
Note that the backend of linkers might have other limits.
Good point.
It's easy to forget/overlook that there are often other "parts" involved in the creation of an executable that may have different limits.

Also, as long as those other parts don't need to refer to items that exceed their limit(s), there is no harm done but, it is not always obvious when a limit that has been exceeded in other parts will play a role.

In those cases, it's always a good idea to write a few test cases to determine the behavior of all the parts involved.

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

paule32

  • Sr. Member
  • ****
  • Posts: 437
Re: FPC 3.2.2 - maximum Length of Identifiers ?
« Reply #10 on: April 24, 2025, 11:29:14 am »
indeed, test cases are good ideas.

currently I don't know how big can .ppu or .o Files be.
When I look into the binary File I see a lot of Numbers from the Header Informations (also the .o bject File).

I check it out: these Numbers are Files which results into the Format of: number.o
The created .a rchive File contains this Files, too.

So far I lay not wrong: Linux open File Limit can be increase but I thinking it is on 32.000 Files by default.
On Windows - I don't know.

Very very much System knowledge to know...
MS-IIS - Internet Information Server, Apache, PHP/HTML/CSS, MinGW-32/64 MSys2 GNU C/C++ 13 (-stdc++20), FPC 3.2.2
A Friend in need, is a Friend indeed.

440bx

  • Hero Member
  • *****
  • Posts: 5264
Re: FPC 3.2.2 - maximum Length of Identifiers ?
« Reply #11 on: April 24, 2025, 12:14:55 pm »
Many limits are imposed by the data types used internally.

For instance, in a PE file, there are fields interpreted as 32 bit signed integers.  that pretty much forces a PE file to be a maximum of 2GB because if it's allowed to be larger than that, there will be offsets that don't fit in a signed 32 bit.

Another thing that is a source of problems is the O/S bitness.  for instance, in the 32bit version of Windows, the affinity bitmask is 32 bits (a DWORD) which causes a problem when there are more than 32 cores.  In 64 bit the affinity is 64 bits which is already at the edge for a PC (processors with 64 cores are fairly common already.)  that's why there are "processor groups" which removes some of those limits.

There are plenty of limits I am not aware of but, I do know that Windows 7 falls all over itself when the number of processes exceeds roughly 2500, I don't know the exact number and I don't know exactly the reason(s) why either but, I do know it cannot gracefully handle that many processes.

Same thing with file size.  Theoretically, the maximum file size is 16TB but, in reality it seems to be about 16TB - 1MB and, that's a bit "rough" because some have reported that once created, deleting it seems to be problematic (I cannot be precise because I have not personally tried it.)

Anyways... it's always fun to push the envelop.  That shows how robust and resilient a piece of software is. 


(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