Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2021-08

Conditional compilation using {$IFOPT ...} and {$IF OPTION(...)}

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

LacaK

Hello,
looking at
https://www.freepascal.org/docs-html/prog/progsu126.html#x139-1400002.4.1

There is mentioned "OPTION(opt)" with comment: "evaluates to TRUE if a compiler option is set (mode MacPas only). It is equivalent to the {$IFOPT } directive."

1. What is equivalent usage for {$IFOPT R+}?
{$IF OPTION(R)} ?

2. What means comment "(mode MacPas only)"?
It will does not work for example for ObjPas mode? In my case Compilation fails ... (with single {$IF OPTION(R)} ) -> Error: Compile time expression: Wanted Boolean but got AnsiString at IF or ELSEIF Can this OPTION be enabled for all modes?

3. Is there way how to do OR with {$IFOPT}?
if I use {$IF OPTION(R) OR OPTION(D)}  I get: "Error: Compile time expression: Wanted Boolean but got AnsiString at IF or ELSEIF" ... So is there way how to do it with {$IFOPT R+D+}?

Thanks
-Laco.

Reply by email

Michael Van Canneyt
to LacaK
LacaK wrote 10 lines
Hello, looking at https://www.freepascal.org/docs-html/prog/progsu126.html#x139-1400002.4.1 There is mentioned "OPTION(opt)" with comment: "evaluates to TRUE if a compiler option is set (mode MacPas only). It is equivalent to the {$IFOPT } directive." 1. What is equivalent usage for {$IFOPT R+}? {$IF OPTION(R)} ?

Yes.

2. What means comment "(mode MacPas only)"?

That you can use it only in macpas mode. In other modes you must use {$IFOPT}

It will does not work for example for ObjPas mode? In my case Compilation fails ... (with single {$IF OPTION(R)} ) -> Error: Compile time expression: Wanted Boolean but got AnsiString at IF or ELSEIF

It only works for mode macpas.

Can this OPTION be enabled for all modes?

Technically yes. Whether that's a good idea, I don't know.

Show quoted text 5 lines
3. Is there way how to do OR with {$IFOPT}? if I use {$IF OPTION(R) OR OPTION(D)}  I get: "Error: Compile time expression: Wanted Boolean but got AnsiString at IF or ELSEIF" ... So is there way how to do it with {$IFOPT R+D+}?

No.

You need to do
{$IFOPT D+}
{$DEFINE DOMYTHING
{$ENDIF}
{$IFOPT R+}
{$DEFINE DOMYTHING
{$ENDIF}
{$IFDEF DOMYTHING}
...
{$ENDIF}

Which I think is the wiser choice in each case, since it avoids repetition and allows you to give a more meaningful name to the 'option'...

Michael.

Reply by email