Conditional Compiling

The compiler supports conditional compiling directivesClosed The orientation components of a vector in space. 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 - Describes a function between input variables and output variables. A function is described as a set of elementary blocks. languages.

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.

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