++IFDEF, ++IFNDEF, ++ELIFDEF

Updated October 2020

++IFDEF <symbol>

    ...

{++ELIFDEF <symbol>

    ...}

++ENDIF

or

++IFNDEF <symbol>

    ...

{++ELIFDEF <symbol>

    ...}

++ENDIF

These directives may be used to conditionally compile sections of code based on whether a specified symbol or structure name has been defined, via DEFINE , DEFTYPE, Compiler Symbol Definitions, DEFTYPE, DEFSTRUCT or DEFALIAS

One typical use is to compile separate bits of code based on a prior symbol definition, for example:

++ifdef VER_WIN

   MAP1 TEMPDIR,"c:\temp"

++elifdef VER_UNIX

   MAP1 TEMPDIR,"/tmp"

++else

   MAP TEMPDIR,"%TEMP%"

++endif

 

In the above example, the symbols VER_WIN or VER_UNIX might have been defined via a DEFINE statement or via the /C switch passed to the compiler.

Another typical use is to avoid redundantly processing a ++INCLUDE module that may have already been compiled. See Avoiding Duplicate INCLUDES.

In the case where the symbol being tested is a DEFALIAS, the ++IFDEF directives test whether the symbol itself exists—i.e. the DEFALIAS was seen by the compiler—not whether the target label or function exists. For example:

defalias fn'bonjour() = fn'hello()

 

++ifdef fn'bonjour()

    ++message fn'bonjour() alias was defined

++eliflbl fn'bonjour()

    ++message fn'hello() function (aliased to  fn'bonjour()) exists

++endif

 

In other words, the ++IFDEF directives treat symbols created by DEFALIAS exactly like those created by DEFINE (without regard to the value of the definition), while the ++IFLBL directives treat DEFALIAS symbols based on the existence of the actual label referenced by the alias.

A ++ifdef ... ++endif statement can be contained in a single source line, for example:

++ifdef TEST_MODE : ? "Running in test mode" :  ++endif

Note however that this is intended to be an accommodation to simplify injection of test or debugging code into source code, and not as an embrace of the generalized concept of jamming multiple statements—especially not pragmas—onto one source line. Developers are encouraged to use the TRACE and DEBUG Statements for messaging that can be enabled at run time rather than compile time.

History

2022 June, A-Shell 6.5.1717, compiler edit 994:  ++IFDEF / ++IFNDEF now treat DEFALIAS definitions as they would symbols defined via DEFINE statements.

2020 October, A-Shell 6.5.1690, compiler edit 938:  Add single-line support for testing and debugging.