are compound conditional directives supposed to work ? lazarus / 62-General ---------------------------------------------------------------------- 440bx · 2018-11-10 00:12 Hello, I was reading the following wiki page http://wiki.freepascal.org/Conditional_compilation which as an example shows: 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 {$IFDEF BLUE AND $IFDEF RED} Form1.Color := clYellow; {$ENDIF} I needed something like that but using or instead of "and".  I tried using "OR" in the conditional and it didn't work (it is what it is.)  My question is: was it supposed to work or is the Wiki page "not quite right" ?  better yet, is there some way to make such a construct work ? (without "helper" conditions and nested ifs) Thanks.  Full example below: 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 OBJFPC}  //// from://// http://wiki.freepascal.org/Conditional_compilation//// {$IFDEF BLUE AND $IFDEF RED} Form1.Color := clYellow; {$ENDIF}   program ConditionalDirectives; //{$define abc0123456789}{$define xyz0123456789} uses  windows   {$ifdef abc0123456789 or $ifdef xyz0123456789}  ,  sysutils  {$endif}  ; begin  // this works as expected   {$ifdef abc0123456789}    writeln('abc is defined');  {$endif}   // this works as expected   {$ifdef xyz0123456789}    writeln('xyz is defined');  {$endif}   //  but this does not work as the wiki page implies it should  //  the "or" seems to be ignored by the compiler   {$ifdef abc0123456789 or $ifdef xyz0123456789}    writeln('either abc or xyz is defined');     writeln('IntToHex 16 ', IntToHex(16, 6));  {$endif}end. ---------------------------------------------------------------------- Blaazen · 2018-11-10 00:53 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 {$if defined(abc0123456789) or defined(xyz0123456789)}...code...{$endif} ---------------------------------------------------------------------- 440bx · 2018-11-10 01:13 That worked. Thank you Blaazen. ---------------------------------------------------------------------- engkin · 2018-11-10 02:12 Also: 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   {$IFNDEF BLUE AND $IFNDEF RED}  WriteLn('not Blue nor Red');  {$ELSE}  WriteLn('Blue or Red');  {$ENDIF} ---------------------------------------------------------------------- 440bx · 2018-11-10 02:59 Quote from: engkin on November 10, 2018, 03:12:01 amAlso: 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   {$IFNDEF BLUE AND $IFNDEF RED}  WriteLn('not Blue nor Red');  {$ELSE}  WriteLn('Blue or Red');  {$ENDIF} @Engkin I'm under the impression that construct doesn't always work (of course, I could be mistaken).  I get that impression because in the example I posted,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  //{$define abc0123456789}{$define xyz0123456789} { some code which doesn't matter here }    {$ifdef abc0123456789 or $ifdef xyz0123456789}    writeln('either abc or xyz is defined');     writeln('IntToHex 16 ', IntToHex(16, 6));  {$endif}end.  the writeln statements are not executed in spite of the fact that xyz0123456789 is defined.  In the same vein, the sysutils unit (see the original example) is not included.   When using that construction, it appears that the condition after the or is not evaluated and if the first condition is false then the entire condition is false even though it should be true because of the or and second condition being true. Maybe I'm missing something... ? ---------------------------------------------------------------------- Thaddy · 2018-11-10 07:00 The only construct that is supposed to work is the example that Blaazen gave. The {$IF Defined()} and {$IF Declared()} type syntax was designed to have more complex  compound operations. The {$IFDEF / $IFNDEF} syntax is not meant to support complex compound syntax without nesting. I would ask on the mailing list if the intended behavior has changed. See https://www.freepascal.org/docs- html/current/prog/progse4.html#x135-1360002.1 and https://www.freepascal.org/docs- html/current/prog/progsu127.html#x140-1410002.4.1 which implies TurboPascal syntax for {$IFDEF} and family and that does NOT allow complex boolean operations. To my knowledge this behavior is not supposed to have changed. [edit] As I recall just now everything after the first name is assumed a comment. 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 untitled;{.$define red}{$define blue}begin{$ifdef red or $ifdef blue} // everything after red is a comment  writeln ('read or blue'); {$endif red or blue} // everything after red is a comment.end.You probably have seen this style used in some libraries to document nested defines, mostly on the {$endif a comment}  parts. In that light it is not a bug, but very confusing... A better example is: 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 untitled;begin{$ifdef CPUARM this code is for arm only} // everything after CPUARM is a comment  writeln ('arm'); {$endif arm specific code} // everything after endif is a comment.end. I have submitted a request for update in the documentation #34532 in Mantis. ---------------------------------------------------------------------- 440bx · 2018-11-10 08:08 Quote from: Thaddy on November 10, 2018, 08:00:46 am The {$IFDEF / $IFNDEF} syntax is not meant to support complex compound syntax without nesting. [edit] As I recall just now everything after the first name is assumed a comment. 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 untitled;{.$define red}{$define blue}begin{$ifdef red or $ifdef blue} // everything after red is a comment  writeln ('read or blue'); {$endif red or blue} // everything after red is a comment.end.You probably have seen this style used in some libraries to document nested defines, mostly on the {$endif a comment}  parts. Thanks Thaddy, that is helpful. That Wiki article seems rather misleading.  It really gives the impression that the construct should work and makes no mention whatsoever of the alternate form Blaazen mentioned which does work as expected. I agree with you that the documentation regarding compound conditionals needs a little "attention". Thanks again. ---------------------------------------------------------------------- Thaddy · 2018-11-10 08:13 I will edit the wiki. [edit] done. But it needs a complete rewrite which I will do later. For now I just corrected the mistakes and made a note. ---------------------------------------------------------------------- creaothceann · 2018-11-10 21:29 You could also do something like this: Code: [Select]{$IFDEF BLUE}  {$DEFINE BLUE_OR_RED}  {$ENDIF} {$IFDEF RED}   {$DEFINE BLUE_OR_RED}  {$ENDIF} //... {$IFDEF BLUE_OR_RED} //... {$ENDIF} Dunno if that falls under your 'without "helper" conditions' condition... ---------------------------------------------------------------------- 440bx · 2018-11-10 23:50 Quote from: creaothceann on November 10, 2018, 10:29:17 pmDunno if that falls under your 'without "helper" conditions' condition... I do consider the additional definitions as "helpers" but I still appreciate your suggestion.  Thank you. ---------------------------------------------------------------------- Thaddy · 2018-11-12 13:58 It is addressed by Michael and the documentation is updated with target 3.2.0. (!!) I have started a complete rewrite of the wiki which will be finished in the next two days. There were so many mistakes that I had to remove *the lot* because much of the example code wasn't even correct. Not only regarding this issue. (I now use some of the old examples to explain what NOT to do... That bad...) It was also overly verbose. So for two days it is correct but not complete and after this wednesday I will ask to review the new entry here. ---------------------------------------------------------------------- Windsurfer · 2018-11-12 14:19 Looking on the bright side, when Big Chimp and I added to the original wiki entry, it was almost impossible to find anything on the subject. Now we will have an expert update. Thanks Thaddy. ---------------------------------------------------------------------- Thaddy · 2018-11-12 15:53 Quote from: Windsurfer on November 12, 2018, 03:19:39 pmLooking on the bright side, when Big Chimp and I added to the original wiki entry, it was almost impossible to find anything on the subject. Now we will have an expert update. Thanks Thaddy. I appreciate the effort, but code in the wiki should be tested before adding it. And that was not the case. It was possible though to find - very implicit, I agree - its proper use. (in my mind, which is not accessible to any and all) I would be much obliged if you read the wiki on wednesday and leave any comments. Mistakes creep in quite easily... And to be fair it wasn't all rubbish. My apologies for the correct parts but still not good enough to stay published. The glass is always half full. ---------------------------------------------------------------------- Windsurfer · 2018-11-12 22:56 Most of the contributions I have made as examples or in the wiki, have been the outcome of days of struggling to understand how to do things. I suspect that is also true for much of the older contributions from many contributors whose main career path was not as a programmer, but as an engineer or whatever. When I saw your mention of Define, it was the first time that I remember seeing it. On the other hand, the LCL is becoming so good that I now rarely use conditional compilation statements. This example code was taken from a project that compiled in 32bit Windows and 64bit Windows and Linux, which was a quite usual combination when it was written. Strangely, it compiled correctly for each with that conditional code, but not without it. 8 and 16 bit versions of any kind were simply not required and therefore irrelevant in the original context. If someone required that, surely a completely exhaustive example was not necessary because enough was given to provide an understanding. 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 var  MyFilesize:  {$ifdef Win32}     Cardinal   {$else}    int64  {$endif} It is great to see things improving. Perhaps you could give a full example for comparison, but would the irrelevant parts not be removed by most programmers? ---------------------------------------------------------------------- Thaddy · 2018-11-13 07:09 Quote from: Windsurfer on November 12, 2018, 11:56:48 pmIt is great to see things improving. Perhaps you could give a full example for comparison, but would the irrelevant parts not be removed by most programmers? I am currently writing and testing complete examples like: 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 var  MyFilesize:  {$ifdef Win32}    Cardinal  {$elseif Win64}    Qword  {$else}    {$error this code is for Microsoft Windows 32/64 Only}  {$endif}Of course the above is no longer necessary: 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 var MyFileSize:NativeUint; ---------------------------------------------------------------------- Windsurfer · 2018-11-14 09:24 Thanks Thaddy. I was not aware of NativeUint. I'll have to study fundamental types again, to see what else has happened. ---------------------------------------------------------------------- marcov · 2018-11-14 09:26 Please don't forget to add a documentation bug, so that the ignoring is added to the $ifdef and $ifndef lemmas of the documentation ---------------------------------------------------------------------- Thaddy · 2018-11-14 10:34 Michael had already done that. Target 3.2 ---------------------------------------------------------------------- Windsurfer · 2018-11-15 07:32 The Free Pascal Programmers' Guide is here: https://freepascal.org/docs-html/prog/prog.html#progch1.html ---------------------------------------------------------------------- Thaddy · 2018-11-15 08:29 Quote from: Windsurfer on November 15, 2018, 08:32:22 amThe Free Pascal Programmers' Guide is here: https://freepascal.org/docs- html/prog/prog.html#progch1.html Yes, but the *fix* is in the documentation sources for the FPC 3.2.0 programmers guide and not yet on-line! You have to build the new documentation yourself for now, until 3.2.0 is released. You can't simply refer to the 3.0.4 documentation. That won't be fixed. Also note the documentation for 3.0.4. is actually correct, but the "comment" feature is simply omitted. For documentation online goes the same as for the current release of the compiler itself: the current compiler is 3.0.4 and the current documentation is 3.0.4. In the wiki that I will finish sometime today, I will make the point that this feature has always been there, at least since fpc 1.9 Stay put. I'll let you know when I am finished with the rewrite. In the mean time try to build the new programmers guide from source... (warning: that is not easy the first time you try!) Or read the raw TeX...