Conditional Compiling

The compiler supports conditional compiling directives in STClosed "Structured text" A high-level language that is block structured and syntactically resembles Pascal, ILClosed "Instruction list" This is a low-level language and resembles assembly, FFLD, and FBDClosed "Function block diagram" A function block diagram describes a function between input variables and output variables. A function is described as a set of elementary blocks languages. Conditional compiling directives condition the inclusion of a part of the program in the generated code based on pragmaClosed A compiler directive communicating additional "pragmatic" information. Pragmas are processed at compile time, not at run time. They pass information to the compiler. Conditional compiling is an easy way to manage several various machine configurations and options in one unique application project.

Conditional compiling uses definitions as conditions. Below is the main syntax:

#ifdef CONDITION
    statementsYES...
#else
    statementsNO...
#endif

If CONDITION has been defined using #define syntax, then the "statementsYES" part is included in the code, else the "statementsNO" part is included. The "#else" statement is optional.


  • Intellisense facilitates the reading by coloring in gray the part of the program which is not active.

How to define conditional compiling directives?

Languages Description
ST and IL Directives must be entered alone on one line of text
FBD Directives must be entered as the text of network breaks
FFLD

Directives must be entered as a network pragma with the icon.

In the example below, if CONDITION has been defined using #define syntax, then the networks 2 to 4 are included in the code, else the networks 5 to 12 are included.

Conditional Compiling in FFLD

The condition "__DEBUG" is automatically defined when the application is compiled in DEBUG mode. This allows you to incorporate some additional statements (such as trace outputs) in your code that are not included in RELEASE mode.

#ifdef      __DEBUG 
Printf('In debug mode', 0, 0, 0, 0);

#endif

Running the Project