%DEF operator

Purpose | Determine if an equate has been previously defined.
Syntax | %DEF({%numeric_equate | $string_equate})
Remarks | The %DEF operator tests whether or not an equate has been defined. If the equate has been defined, %DEF returns TRUE (non-zero); or FALSE (zero) if it has not be defined. PowerBASIC automatically defines the equates in the following table according to the PowerBASIC compiler being used. Please note the references to other PowerBASIC compilers are included for those writing programs that may be compilable by more than one PowerBASIC compiler.

Equate | Definition
%PB_CC32 | Pre-defined as TRUE (non-zero) in PB/CC for Windows, but is not defined in other compilers.
%PB_DLL16 | Pre-defined as TRUE (non-zero) in PB/DLL 16-bit, but is not defined in other compilers.
%PB_DLL32 | Synonym of %PB_WIN32
%PB_WIN32 | Pre-defined as TRUE (non-zero) in PB/Win 32-bit, but is not defined in other compilers.
%PB_REVISION | Pre-defined as the hex revision (10.00 = &H1000).
%PB_REVLETTER | Pre-defined as the ASCII code of the revision letter (a = &H61), or &H20 if there is no revision letter.
%PB_EXE | Pre-defined as TRUE (non-zero) if compiling to EXE or as FALSE (zero) if compiling to DLL (PB/Win only) or SLL format. The equate %PB_EXE is always defined in PowerBASIC, so %DEF(%PB_EXE) will always be evaluated as TRUE. The difference being the value assigned to the equate by the compiler. See the examples below.

These can be used in conjunction with #IF as a compiler directive to selectively include or exclude code from the compiled file.

See also | #IF, Numeric Equates, Built-in numeric equates, String Equates, Built-in string equates

Example

' 1. Conditional compilation for PB/CC or PB/Win

#IF %DEF(%PB_CC32)

'Assume PB/CC

#COMPILE EXE "\PBCC\APPS\MYPROG.EXE"

#ELSE

'Assume PB/Win

#COMPILE DLL "MYAPP.DLL"

#ENDIF

' 2. Conditional compilation for EXE or DLL

#IF %PB_EXE

' we are compiling to an EXE (PB/CC or PB/Win)

FUNCTION PBMAIN

[statements]

END FUNCTION

#ELSE

' we are compiling to a DLL (PB/Win)

FUNCTION PBLIBMAIN

[statements]

END FUNCTION

#ENDIF