Conditional Compiling

The compiler supports conditional compiling directives in ST, IL, FFLD, and FBD languages.

  • Conditional compiling directives condition the inclusion of a part of the program in the generated code based on pragma.
  • 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.

This 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?

Language Description

FBD Language

Directives must be entered as the text of FBD Network Breaks

FFLD Language

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

In this example image:

  • 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

IL Language

ST Language

Directives must be entered alone on one line of text.


  • Conditional compilation do not apply to actions in an SFC step.

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

See Also

also see "Run the Project" on page 1