(* and *) are equal to { and } only older...
Thanks for the good explanations. But back to one of my initial questions: Shouldn't the compiler ignore what is in quotes?But it does ignore it.... Always has.... It translates to a string literal and is stored as is. Except for escaped characters which are first evaluated and then stored.
@Mark: you are wrong, see the docs about chicken and egg, (* was first, {} is TP style.:
https://www.freepascal.org/docs-html/ref/refse2.html
So we can conclude that the curly brackets are always active, regardless of the surrounding context.Yes
fred@fred-80m0 ~> fpc test.pas
Free Pascal Compiler version 3.2.2 [2021/07/09] for x86_64
Copyright (c) 1993-2021 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling test.pas
test.pas(3,29) Warning: Comment level 2 found
test.pas(6,5) Fatal: Unexpected end of file
Fatal: Compilation aborted
Error: /usr/bin/ppcx64 returned an error exitcode
In your case you can use proper real old school comments as already suggested: (*...*).
So we can conclude that the curly brackets are always active, regardless of the surrounding context.
The code inside the start of a comment is ignored until the compiler sees a closing of the comment.
...
But this compiles:
program Project1; begin writeln('ok//'); end.
So, for single line comments the rule the rule does not apply.
The code inside the start of a comment is ignored until the compiler sees a closing of the comment.
<snip>
wp - no, not always. In some dialects, more theoretican practical, like ANSI Pascal the following are correct and complete comments:
(* bla-bla-vla }
{ bla-vla-vla *)
Actually, TP (if not USCD) violated the standard and hardware history when making them incompatible. But doing so they enables erzats nested comments, so they did good
On the contrary. (. 1..2 ] and [ 3 .. 4 .) are still valid sets/ranges. Inconsistent, but practical :-)
fpc dont like this one too:
program test; { I am a comment with this: { something... } begin end.
Result:Quotefred@fred-80m0 ~> fpc test.pas
Free Pascal Compiler version 3.2.2 [2021/07/09] for x86_64
Copyright (c) 1993-2021 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling test.pas
test.pas(3,29) Warning: Comment level 2 found
test.pas(6,5) Fatal: Unexpected end of file
Fatal: Compilation aborted
Error: /usr/bin/ppcx64 returned an error exitcode
That depends upon the mode. In modes FPC and ObjFPC FPC allows nested comments, so you can have { foo { bar } blubb }, while in modes TP and Delphi you need to alternate the comment style for this to compile: { foo (* bar *) blubb }. This is why your code fails as the compiler detects a second level comment and expects as many closing brackets to finish of the comment(s).
That depends upon the mode. In modes FPC and ObjFPC FPC allows nested comments, so you can have { foo { bar } blubb }, while in modes TP and Delphi you need to alternate the comment style for this to compile: { foo (* bar *) blubb }. This is why your code fails as the compiler detects a second level comment and expects as many closing brackets to finish of the comment(s).
When you say "alternate" do you literally mean /alternate/ or is there still a two-deep limit?
For both Delphi and modes Delphi and TP only two levels are supported. With the full blown nested comments of the other modes you can have arbitrary levels (well, I think there is some limit in the compiler).