The new gem for people porting C header but don't use mode ObjFPC lazarus / 62-General ---------------------------------------------------------------------- jiaxing2 · 2020-05-10 13:24 It's a gem. I wonder why I didn't know it sooner  https://www.freepascal.org/docs-html/ref/refsu87.html p/s: for people that don't know, array of const is sticked with mode ObjFPC. ---------------------------------------------------------------------- lucamar · 2020-05-10 13:52 Quote from: jiaxing2 on May 10, 2020, 03:24:36 pmp/s: for people that don't know, array of const is sticked with mode ObjFPC. and mode Delphi, though (IIRC) there are differences when using the cdecl modifier. ---------------------------------------------------------------------- Thaddy · 2020-05-10 14:17 Quote from: lucamar on May 10, 2020, 03:52:49 pmQuote from: jiaxing2 on May 10, 2020, 03:24:36 pmp/s: for people that don't know, array of const is sticked with mode ObjFPC. and mode Delphi, though (IIRC) there are differences when using the cdecl modifier. No there is only a difference between Delphi itself and {$mode delphi} AFAIK. And that difference is simply a feature that Delphi does not support. I think you mean varargs, like this: https://freepascal.org/docs-html/ref/refsu87.html That is supported by FPC but not by Delphi. But FPC also supports it in {$mode delphi} To be clear, Delphi also supports varargs, but can not write it as an open array. It leaves it out of the parameter list. This latter varargs syntax is also supported by FPC, but the difference is clear. ---------------------------------------------------------------------- jiaxing2 · 2020-05-10 17:17 Quote from: Thaddy on May 10, 2020, 04:17:31 pmQuote from: lucamar on May 10, 2020, 03:52:49 pmQuote from: jiaxing2 on May 10, 2020, 03:24:36 pmp/s: for people that don't know, array of const is sticked with mode ObjFPC. and mode Delphi, though (IIRC) there are differences when using the cdecl modifier. No there is only a difference between Delphi itself and {$mode delphi} AFAIK. And that difference is simply a feature that Delphi does not support. I think you mean varargs, like this: https://freepascal.org/docs-html/ref/refsu87.html That is supported by FPC but not by Delphi. But FPC also supports it in {$mode delphi} To be clear, Delphi also supports varargs, but can not write it as an open array. It leaves it out of the parameter list. This latter varargs syntax is also supported by FPC, but the difference is clear. I don't care about Delphi compatibility, so FPC supports it is enough. The fact is array of const sticked with mode ObjFPC caused trouble for me when porting C code with VLAs. I want code using mode FPC could use my units so my discover of FPC's varargs support is a gem as it doesn't stick with any particular mode! ---------------------------------------------------------------------- Thaddy · 2020-05-10 17:48 All modes that support units can be intermixed on a per unit basis. So your main program may be mode objfpc, but still can use units compiled in mode delphi too...and the other way around. The compiler handles  this automatically. ---------------------------------------------------------------------- Thaddy · 2020-05-10 17:56 Quote from: jiaxing2 on May 10, 2020, 07:17:47 pmThe fact is array of const sticked with mode ObjFPC caused trouble for me when porting C code with VLAs. It isn't... It also works in mode delphi as I explained. ---------------------------------------------------------------------- jiaxing2 · 2020-05-10 19:36 Quote from: Thaddy on May 10, 2020, 07:56:11 pmQuote from: jiaxing2 on May 10, 2020, 07:17:47 pmThe fact is array of const sticked with mode ObjFPC caused trouble for me when porting C code with VLAs. It isn't... It also works in mode delphi as I explained. And I don't do Delphi ---------------------------------------------------------------------- jiaxing2 · 2020-05-10 19:39 Quote from: Thaddy on May 10, 2020, 07:48:02 pmAll modes that support units can be intermixed on a per unit basis. So your main program may be mode objfpc, but still can use units compiled in mode delphi too...and the other way around. The compiler handles  this automatically. Yes. I know. But the program uses it. If I use array of const, the syntax will be like this: 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 Function PrintF2(fmt : pchar; Args : Array of const); cdecl;                               external ’c’ name ’printf’; Code called it will be like this: 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 PrintF2(’%d %d\n’,[1,1]); // I don't think this syntax is supported on mode FPC If I just use varargs: 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  Function PrintF1(fmt : pchar); cdecl; varargs;                                 external ’c’ name ’printf’; Code called it will be like this: 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 PrintF1(’%d %d\n’,1,1); ---------------------------------------------------------------------- jiaxing2 · 2020-05-10 19:44 The only problem is the h2pas conversion tool. It uses mode FPC by default but translates VLAs into array of const. If I manually replace array of const with varargs when compile under mode FPC it will fails because of overloaded function have the same parameters error. I have to find and delete the declaration without varargs manually. This is annoying. h2pas generates two declarations for one function with VLAs: one removed the VLAs part, one translated to array of const.