Please enable JavaScript to view this site.

The following directives may be used to mark sections of code to be conditionally compiled, based on whether a symbol, variable or label has been defined, or whether a constant expression is true or false. They are analogous to the IF/ELSEIF/ELSE/ENDIF statements except that they affect the operation of the compiler—determining which statements are compiled and which are ignored—rather than the runtime interpreter. The feature requires compiler switch /RC or /X:1 or higher.

Directive

Description

++IF, ++ELIF

Conditionals based on evaluating a constant expression.

++IFDEF, ++IFNDEF, ++ELIFDEF

Conditionals based on whether the specified symbol or structure has been previously defined.

++IFLBL, ++INFLBL, ++ELIFLBL

Conditionals based on whether specified label has been defined.

++IFMAP, ++IFNMAP, ++ELIFMAP

Conditionals based on whether specified variable has been mapped.

++ELSE

Used as an optional final clause preceded by any other type of ++IFxxx and ++ELIFxxx statements. The lines following the ++ELSE up to the ++ENDIF are compiled only if all of the preceding clauses were false.

++ENDIF

Marks the end of the conditional construct.

 

Example 1

++IFDEF GUI

PROGRAM MYPROG,1.0G(100)

<source code implementing GUI version here>

++ELSE

PROGRAM MYPROG,1.0(100)

<source code implementing text version here>

++ENDIF

 

The above illustrates one way to use conditional compilation to conditionally create either a GUI or text version of your RUN file, starting from the same source file. Previously you could only do the same thing with runtime conditions (which may still be a better option in most cases), but in some cases, you may prefer to have two separate versions of the RUN (perhaps to keep the size down, or to simplify runtime debugging.) Note that the symbol GUI would have had to have been defined somewhere prior to the compiler seeing these statements; see below for how to define symbols on the command line.

Also note that we used two different versions of the PROGRAM statement in the above example, so that you can easily tell which RUN version you have by displaying it with DIR/V.

Example 2

++IF APPVER = 1

   ++MESSAGE Compiling Version 1

   ++ver1.bsi

++ELIF APPVER = 2

   ++MESSAGE Compiling Version 2

   ++ver2.bsi

++ELSE

   ++ERROR No APPVER defined!

++ENDIF

 

This illustrates the IF/ELIF/ELSE/ENDIF construct, used to select which ++INCLUDE file to use based on the defined APPVER. See the ???? and ++++ERROR statements.

Example 3

++IFDEF SBX

   ++PRAGMA SBX

   <retrieve parameters, SBX setup, etc.>

++ENDIF

 

This illustrates a simple way to allow a single source file to be compiled as either an SBX or a RUN file. The SBX symbol would need to be defined on the compiler command line, e.g. COMPIL MYPROG/X:2/C:SBX=1.

Example 4

++IFDEF MODE_SBX

   ++PRAGMA SBX

   <retrieve parameters, SBX setup, etc.>

++ELIFDEF MODE_LIT

   ++PRAGMA FORCE_FSPEC SYS:MYPROG.LIT

   <command line parsing>

++ELSE

   <standard RUN setup>

++ENDIF

 

This illustrates an approach to generating either an SBX, LIT, or RUN from the same source file. The MODE_SBX or MODE_LIT symbols would need to be defined on the compiler command line, e.g. COMPIL MYPROG/X:2/C:MODE_SBX=1.

See Also

History

2013 March, A-Shell 6.1.1346:  Add ++ELIFDEF and ++ELIFMAP

2011 November, A-Shell 6.0.1240:  Increase maximum nesting levels for conditional compilation statements from 5 to 13.

Created with Help+Manual 9 and styled with Premium Pack Version 5 © by EC Software