constant declarations not working as they do in Delphi lazarus / 62-General ---------------------------------------------------------------------- 440bx · 2019-02-10 01:20 Hello, FPC will not compile the following program:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$APPTYPE CONSOLE} program ArrayConstError; procedure DoIt;const  LINE_CNT   = 2;   DataBuf    : packed array[1..LINE_CNT] of packed array[0..1023] of char    = (#0, #0);   // FPC does NOT accept this construction.  Delphi 2.0 does.   DataArray  : packed array[1..LINE_CNT] of pchar  = (DataBuf[1], DataBuf[2]); begin  writeln(DataBuf[1]);  writeln(DataBuf[2]);   writeln(DataArray[1]);  writeln(DataArray[2]);end; begin  DoIt;end.  When attempting to compile the program above, FPC returns the following errors:Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Compile Project, Mode: Default, Target: lib\i386-win32\ArrayConstError.exe: Exit code 1, Errors: 2ArrayConstError.lpr(13,18) Error: Incompatible types: got "Array[0..1023] Of Char" expected "PChar"ArrayConstError.lpr(13,30) Error: Incompatible types: got "Array[0..1023] Of Char" expected "PChar"  Delphi version 2.0 compiles it without complaint.    I do not know if it compiles with other versions of Delphi.  Assistance to determine if it does or not is appreciated. Should this be considered a "Delphi compatibility mode" bug ? ---------------------------------------------------------------------- engkin · 2019-02-10 01:25 I don't see mode Delphi around the top, isn't it needed? ---------------------------------------------------------------------- 440bx · 2019-02-10 01:40 Quote from: engkin on February 10, 2019, 02:25:57 amI don't see mode Delphi around the top, isn't it needed? I tried it.  It didn't make any difference. ---------------------------------------------------------------------- Cyrax · 2019-02-10 02:06 Changing your code to this makes it to compile successfully. FPC 3.3.1 trunk r41244 (i386-linux, i386-win32). Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ...DataArray  : packed array[1..LINE_CNT] of pchar    = (@DataBuf[1], @DataBuf[2]);... ---------------------------------------------------------------------- 440bx · 2019-02-10 02:11 Quote from: Cyrax on February 10, 2019, 03:06:09 amChanging your code to this makes it to compile successfully. FPC 3.3.1 trunk r41244 (i386-linux, i386-win32). Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i ...DataArray  : packed array[1..LINE_CNT] of pchar    = (@DataBuf[1], @DataBuf[2]);... You're right, it does but, I don't think it should be necessary.  Even when specifying {$MODE DELPHI} it doesn't compile.  I believe it should. Strictly from a compiler's definition viewpoint, FPC - as Delphi does - considers zero based arrays of char to be assignment compatible with pchar, because of that, the use of the address of operator should not be necessary. ETA: I am using FPC v3.0.4 under Windows 7 64bit. @Cyrax: thank you, I do appreciate your offering a solution. ---------------------------------------------------------------------- ASerge · 2019-02-10 04:34 Quote from: 440bx on February 10, 2019, 02:20:18 amDelphi version 2.0 compiles it without complaint.    I do not know if it compiles with other versions of Delphi. Delphi 10.3 also comple and code work right. Quote from: 440bx on February 10, 2019, 03:11:23 amStrictly from a compiler's definition viewpoint, FPC - as Delphi does - considers zero based arrays of char to be assignment compatible with pchar, because of that, the use of the address of operator should not be I agree with you, it is somewhat wrong that need to specify the @. This will show garbage: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$APPTYPE CONSOLE}program ArrayConstError; procedure DoIt;const  LINE_CNT = 2;  DataBuf: packed array[1..LINE_CNT] {of packed array[0..1023] of Char} of PChar    = ('Some'#0, #0);  DataArray: packed array[1..LINE_CNT] of PChar = (@DataBuf[1], @DataBuf[2]);begin  Writeln(DataBuf[1]);  Writeln(DataArray[1]);end; begin  DoIt;  Readln;end. ---------------------------------------------------------------------- 440bx · 2019-02-10 10:30 Quote from: ASerge on February 10, 2019, 05:34:52 amDelphi 10.3 also comple and code work right. Thank you for checking the behavior in other versions of Delphi.   Given that the discrepancy is consistent, I will report it as a bug. Quote from: ASerge on February 10, 2019, 05:34:52 amThis will show garbage: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$APPTYPE CONSOLE}program ArrayConstError; procedure DoIt;const  LINE_CNT = 2;  DataBuf: packed array[1..LINE_CNT] {of packed array[0..1023] of Char} of PChar    = ('Some'#0, #0);  DataArray: packed array[1..LINE_CNT] of PChar = (@DataBuf[1], @DataBuf[2]);begin  Writeln(DataBuf[1]);  Writeln(DataArray[1]);end; begin  DoIt;  Readln;end.Unfortunately, in that case, FPC and Delphi behave the same way.  The use of @ is incorrect but, I reported that problem/bug a while back and, it doesn't look like that problem/bug will be corrected because it is consistent with Delphi.