"program" keyword, Borland compatibility and documentation lazarus / 62-General ---------------------------------------------------------------------- Arioch · 2022-10-01 16:00 This is minor issue, but for the record. Quote from: Free Pascal Reference guide16.1  Programs A Pascal program consists of the program header, followed possibly by a “uses” clause, and a block.   ... The program header is provided for backwards compatibility, and is ignored by the compiler. Well, the latter is not true. It is NOT ignored and it is not drop-in compatible too. 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 {$mode tp}program; beginend. and 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 {$mode delphi}program; beginend. result in Quoteproject1.lpr(2,8) Fatal: Syntax error, "identifier" expected but ";" found So, not ignored. It, perhaps, was indeed ignored in TP, but it is not ignored in Delphi, see the error message near resource directive in the attached screenshot Quote from: Free Pascal Programmer’s GuideD.2  TP mode This mode is selected by the  $MODE TP  switch. It tries to emulate... this deviation is not mentioned Quote from: Free Pascal Programmer’s Guide8.6  When porting Turbo Pascal code neither ---------------------------------------------------------------------- MarkMLl · 2022-10-01 16:12 It says "program header" and "program" without a following identifier is not a valid program header. I'm not sure, but the requirement might have been tweaked a bit when InstantFPC was introduced. https://wiki.freepascal.org/InstantFPC mentions the compiler's -o option for setting the name. MarkMLl ---------------------------------------------------------------------- Bogen85 · 2022-10-01 16:14 The .lpr extension is for a Lazarus project, so if you are building from Lazarus, that will likely be what it wants. Occasionally I build Lazarus projects from the command line using lazbuild but for all my own software projects I don't use Lazarus. So I assume you are trying to build via the project manager, and not build your example as a standalone program, which I don't know off hand how to do in Lazarus, as I don't use it. When using fpc outside of the GUI, a program with the .pas extension named the same as the program name in the source code works fine. 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 {$mode delphi}program ProgramName; beginend.  A source file with the above content named ProgramName.pas is fine and is accepted by fpc and will result in the executable ProgramName (or ProgramName.exe if on Windows). ---------------------------------------------------------------------- Arioch · 2022-10-01 16:29 Well, TP/BP/BPW 5.5/6.0/7.0 certainly provided for program keyword without identifier. And the Delphi versions i think of did too, though i did not test often. Delphi has a ready templates, that TP/BP did not. So, in the modes that claim compatibility - this syntax is expected to be tolerated. Or, otherwise, explicitly documented as incompatibility. > is not a valid program header. that is a bit of scholasticism, biut to me if the header was actually ignored - the cmpiler would never know if it is valid or not, it would just fast-forward until the end, and get over. But this header is no more ignored actually, if it ever was. It is now parser for ID for $R directives, probably even in Sybil :-) ---------------------------------------------------------------------- Arioch · 2022-10-01 16:40 BTW, dynamic arrays AFAIR also are not fully compatible without that being mentioned in the docs 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 program Project1; {$mode delphi} var a: array of integer; begin  SetLength(a,2);  a := nil;   Writeln(Length(a));  Writeln(nil = a);  // project1.lpr(12,15) Error: Operator is not overloaded: "Pointer" = "{Dynamic} Array Of LongInt"   Readln;end. ---------------------------------------------------------------------- PascalDragon · 2022-10-01 17:54 Quote from: Arioch on October 01, 2022, 06:00:50 pmThis is minor issue, but for the record. Quote from: Free Pascal Reference guide16.1  Programs A Pascal program consists of the program header, followed possibly by a “uses” clause, and a block.   ... The program header is provided for backwards compatibility, and is ignored by the compiler. Well, the latter is not true. It is NOT ignored and it is not drop-in compatible too. What is meant here is that the whole program header can be left out. E.g. the following is a valid Pascal 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 beginend. Quote from: Arioch on October 01, 2022, 06:29:10 pmWell, TP/BP/BPW 5.5/6.0/7.0 certainly provided for program keyword without identifier. And the Delphi versions i think of did too, though i did not test often. Delphi has a ready templates, that TP/BP did not. Current Delphi allows this as well. Please report as a bug. (Sidenote: Delphi also allows the use of the file list in the program header without a program identifier, so program (Input, Output) is valid as well) Quote from: Arioch on October 01, 2022, 06:40:59 pmBTW, dynamic arrays AFAIR also are not fully compatible without that being mentioned in the docs 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 program Project1; {$mode delphi} var a: array of integer; begin  SetLength(a,2);  a := nil;   Writeln(Length(a));  Writeln(nil = a);  // project1.lpr(12,15) Error: Operator is not overloaded: "Pointer" = "{Dynamic} Array Of LongInt"   Readln;end.     It works if you do a = nil. Please report as a bug. ---------------------------------------------------------------------- Arioch · 2022-10-01 18:37 https://gitlab.com/freepascal.org/fpc/source/-/issues/39934 https://gitlab.com/freepascal.org/fpc/documentation/-/issues/39324 https://gitlab.com/freepascal.org/fpc/source/-/issues/39933 ---------------------------------------------------------------------- d.ioannidis · 2022-10-02 23:03 Hi,   BTW, Delphi 7 ( Pro Build 4.453 ) help writes : QuoteThe program heading specifies the program's name. It consists of the reserved word program, followed by a valid identifier, followed by a semicolon. The identifier must match the project file name. In the previous previous example, since the program is called Editor, the project file should be called Editor.dpr. In standard Pascal, a program heading can include parameters after the program name: program Calc(input, output); Borland's Delphi compiler ignores these parameters. And in the Object Pascal grammar has : QuoteGoal -> (Program | Package | Library | Unit) Program -> [PROGRAM Ident ['(' IdentList ')'] ';']            ProgramBlock '.' Unit -> UNIT Ident [PortabilityDirective] ';'         InterfaceSection         ImplementationSection         InitSection '.' .............. IdentList -> Ident ','... .............. Ident -> .............. regards, ---------------------------------------------------------------------- KodeZwerg · 2022-10-02 23:45 Quote from: d.ioannidis on October 03, 2022, 01:03:43 amBTW, Delphi 7 ( Pro Build 4.453 ) help writes...A more current version can be reviewed here -> https://docwiki.embarcadero.com/RADStudio/en/Programs _and_Units_(Delphi) Best regards. ---------------------------------------------------------------------- Arioch · 2022-10-03 18:50 Quote from: d.ioannidis on October 03, 2022, 01:03:43 am  BTW, Delphi 7 ( Pro Build 4.453 ) help writes : We all know that documentation is often faulty, be it Delphi or FPC or any other program. The particularly nightmarish example o both compielr and docs broken was Delphi 2009, IMHO Frankly, this is a realy edge case. I believe it would be better to fix it one time in the compiler and make transiting programmers less confused. But since those proigrammers would have to learn how to enable mode tp or mode delphi - they can learn to check "program" keyword too. So, the opposite approach (do not fix incompatibility, but document it in 2+ articles in the help as intended one) is fine too. Slightly worse IMHO but not much. Just fix it by any of the means and forget :-) P.S. BTW, expectedly in Delphi XE2 the same works with "library" clause for DLL projects. Library (Input, Output); did not work though. Not that i tried hard, maybe just a typo. ---------------------------------------------------------------------- MarkMLl · 2022-10-03 19:10 Quote from: Arioch on October 03, 2022, 08:50:53 pmWe all know that documentation is often faulty, be it Delphi or FPC or any other program. The particularly nightmarish example o both compielr and docs broken was Delphi 2009, IMHO Almost as nightmarish as your lack of a spieling chuckler :-) Not intended personally... but does /any/ language permit "lr" at the end of a word? MarkMLl ---------------------------------------------------------------------- Arioch · 2022-10-03 19:26 i am really typing on the run, sorry  :-) ---------------------------------------------------------------------- KodeZwerg · 2022-10-03 19:48 Quote from: MarkMLl on October 03, 2022, 09:10:55 pmNot intended personally... but does /any/ language permit "lr" at the end of a word?Yes, english/american does    https://www.wordnik.com/words/reproachablr and somewhere i also read about tumblr ---------------------------------------------------------------------- Bogen85 · 2022-10-03 20:01 Not sure where they found these: https://www.thefreedictionary.com/words-that-end-in-lr or these: https://findwords.info/ends/lr ---------------------------------------------------------------------- MarkMLl · 2022-10-03 20:09 Wherever it was... I don't want to go there. I admit to being humbled by my possible error... but suspect that the case is still so egregious that people have gone out of their way to try to find examples. MarkMLl ---------------------------------------------------------------------- Bart · 2022-10-03 20:37 Quote from: Arioch on October 03, 2022, 08:50:53 pmWe all know that documentation is often faulty, be it Delphi or FPC or any other program. With that in mind, we can dismiss all bugreports: "well, the docs are just wrong about the behaviour, the behaviour as is, is the correct behaviour". Makes our lives that much easier  Bart ---------------------------------------------------------------------- Arioch · 2022-10-03 21:29 well, VLDLR looks cute. Sadly it was acronym... ---- Bart, well, wiser people than us told it already :-) https://www.wired.com/story/its-not-a-bug-its-a-feature/ ---------------------------------------------------------------------- PascalDragon · 2022-10-04 11:41 Quote from: Arioch on October 03, 2022, 08:50:53 pmWe all know that documentation is often faulty, be it Delphi or FPC or any other program. The same is also true for the program itself. The thing is, for compatibility one needs to decide which is the source of truth: the documentation or the implementation. Both can have bugs. We decided that for compatibility we only go for the documentation, not the implementation.