Forum > FPC development
unexpected behavior in FPC v3.2.2
440bx:
Hello,
Consider the following program:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- {$define (NoClosingParenthesis} { no complaint about missing parenthesis }{$define NoOpeningParenthesis)} { no complaint about missing parenthesis } program _DirectivesParentheses; beginend. Note that the compiler directives have mismatched parentheses, yet the compiler compiles that code without complaints.
Comments welcome.
dbannon:
Its one or the other of -
[x] You have discovered a new compiler directive.
[x] The compiler does not check for matching Parenthesis inside a comment.
I think I prefer the latter. A {$define } is a comment when you think about it, a comment left for the compiler rather than a human reader but still a comment.
Davo
MarkMLl:
--- Quote from: dbannon on October 27, 2024, 10:23:12 am ---Its one or the other of -
[x] You have discovered a new compiler directive.
[x] The compiler does not check for matching Parenthesis inside a comment.
I think I prefer the latter. A {$define } is a comment when you think about it, a comment left for the compiler rather than a human reader but still a comment.
Davo
--- End quote ---
What is the behaviour of the -d option on the commandline (with appropriate shell quoting/escaping)?
What is the behaviour of {$ifdef with those mismatched parentheses?
Can't check myself, out in a few mins.
MarkMLl
440bx:
--- Quote from: dbannon on October 27, 2024, 10:23:12 am ---I think I prefer the latter. A {$define } is a comment when you think about it, a comment left for the compiler rather than a human reader but still a comment.
--- End quote ---
It's a comment but one that must comply with some rules. For instance:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{$ifdef (SomeName} // note the missing closing parenthesisdoes NOT compile because the compiler insists on having a closing parenthesis in that "comment".
It was a reasonable thought but, directives are comments that are held to some rules they must follow. Parentheses must be matched because they cannot be part of the identifier, therefore a lone parenthesis is an extraneous character.
marcov:
IIRC there is a "feature" inherited from turbo pascal that trailing tokens of a $define are ignored. That explains the second one.
Navigation
[0] Message Index
[#] Next page