Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to define {$IFDEF} for more than one directive at once?

Is it possible to define more than one conditional in one {$IFDEF} directive ?
I would like to have syntax like this:

{$IFDEF Condition1 OR Condition2} DoSomething; {$ENDIF} {$IFDEF Condition1 AND Condition2} DoSomethingElse; {$ENDIF} 

Thanks

like image 886
Martin Reiner Avatar asked Jan 04 '12 09:01

Martin Reiner


People also ask

Can you have Ifdef inside Ifdef?

Syntax. Conditional compilation can be achieved with Verilog `ifdef and `ifndef keywords. These keywords can appear anywhere in the design and can be nested one inside the other.

Where is Ifdef defined?

The meaning of #ifdef is that the code inside the block will be included in the compilation only if the mentioned preprocessor macro is defined. Similarily #if means that the block will be included only if the expression evaluates to true (when replacing undefined macros that appears in the expression with 0).

What is the difference between #if and #ifdef?

#if checks for the value of the symbol, while #ifdef checks the existence of the symbol (regardless of its value).

What is the difference between Ifdef and Ifndef?

Use the #ifdef statement when you want to compile a section only if a specified expression has been defined with #define. Use #ifndef when you want to compile a section only if a specified expression has not been defined.


2 Answers

You would need to use $IF instead:

{$IF Defined(Condition1) or Defined(Condition2)} DoSomething; {$IFEND} 
like image 72
David Heffernan Avatar answered Sep 19 '22 19:09

David Heffernan


In case you have to support old Delphis (without the support for the $IF metadirective), you can use one simple and one ugly workaround:

//AND {$IFDEF Cond1}{$IFDEF Cond2}DoSomething{$ENDIF}{$ENDIF}   //OR {$UNDEF Cond1OrCond2} {$IFDEF Cond1}{$DEFINE Cond1OrCond2}{$ENDIF} {$IFDEF Cond2}{$DEFINE Cond1OrCond2}{$ENDIF} {$IFDEF Cond1OrCond2}DoSomething{$ENDIF} 

If you are repeating the test more than once, first case should be rewritten as follows.

{$UNDEF Cond1AndCond2} {$IFDEF Cond1}{$IFDEF Cond2}{$DEFINE Cond1AndCond2{$ENDIF}{$ENDIF}   {$IFDEF Cond1AndCond2}DoSomething{$ENDIF} 
like image 34
gabr Avatar answered Sep 18 '22 19:09

gabr