| UMBC CMSC 211 |
#ifdef DEBUG
printf( "At debug point 27: \n" );
printf( " A = %d\n", A );
printf( " B = %d\n", B );
#endif
That allows us to compile the block of code based on some condition. It has wide usage and is a very handy technique.
In assembly language, we have something similiar as:
IF condition
... lines assembled if 'condition' is true
ELSE
... lines assembled if 'condition' is false
ENDIF
IF condition1
... lines assembled if 'condition1' is true
ELSEIF condition2
... lines assembled if 'condition1' is false and 'condition2' is true
ELSEIF condition3
... lines assembled if 'condition1' is false and 'condition2' is false and 'condition3' is true
ELSE
... lines assembled if 'condition1' and 'condition2' and 'condition3' are false
ENDIF
Your condition might be:
Actually, we have even more:
Directive Description
IF Assembles block if expression is true (nonzero)
IFE Assembles block if expression is false (zero)
IFB Assembles block if expression is blank
IFNB Assembles block if expression is not blank
IFDEF Assembles block if symbol is defined
IFNDEF Assembles block if symbol is not defined
IFDIF Assembles block if arguments are different
IFDIFI Assembles block if arguments are different, case insensitive
IFIDN Assembles block if arguments are identical
IFIDNI Assembles block if arguments are identical, case insensitive
ELSE Begins alternate conditional block
ELSEIF Begins alternate block with a new condition
ENDIF Ends conditional block
There are ELSE versions of each IF condition:
In C, when we are including a bunch of header files, you will ofthen see something like:
#ifndef __GARY_HEADER__ #define __GARY_HEADER__ ...some stuff here #endif
IFNDEF ABC_Included
... some stuff here
ABC_Included EQU 0
ENDIF
EQ EQual NE Not Equal LT Less Than LE Les than or Equal to GT Greater Than GE Greater than or Equal to