Search code examples
compilationversionconditional-statementsfreepascalfpc

Can we use > (greater than) or < (lesser than) on compile conditionals with the version number on Free Pascal


I've seen conditional compile directives with expressions related to the version of the compile, but I'm unable to locate them again.

How would I correctly write this in Free Pascal?

program do_stuff;
begin
{$IF VER > 2.4}
// Some code here
{$ENDIF}
end.

Thanks.


Solution

  • This is a copy and paste from Free Pascal Website:

    {$IF (FPC_VERSION > 2) or  
         ((FPC_VERSION = 2)  
           and ((FPC_RELEASE > 0) or  
                ((FPC_RELEASE = 0) and (FPC_PATCH >= 1))))}  
       {$DEFINE FPC_VER_201_PLUS}  
     {$ENDIF}  
    {$ifdef FPC_VER_201_PLUS}  
    {$info At least this is version 2.0.1}  
    {$else}  
    {$fatal Problem with version check}  
    {$endif}  
    

    It should do what you require, but you'll have to adjust the figures.