Conditional Pragmas

NOTICE

NOTICE
NOTICE
NOTICE

NOTICE

NOTICE

You use conditional pragmas in the implementations of ST POUs. CODESYS does not evaluate these conditional pragmas when you use them in the declaration part.

The purpose of conditional pragmas is to influence how code is generated in the pre-compile or compile process. The ST implementation language supports these pragmas.

With conditional pragmas, you influence whether or not implementation code is taken into account for the compile. For example, you can make this dependent on whether a specific variable is declared, whether a specific POU exists, etc.

Pragma

Description

‎{define <identifier> <string>}‎

The value can be queried and compared with ‎hasvalue‎ later on.

‎{undefine <identifier>}‎

The ‎{define}‎ statement of the identifier ‎<identifier>‎ is removed, and the identifier is "undefined" again from now on. The pragma is ignored when the specified identifier is not defined at all.

‎{IF <expr>}...‎

‎{ELSIF <expr>}...‎

‎{ELSE}...‎

‎END_IF}‎

These are pragmas for the conditional compile.

The specified expressions ‎<expr>‎ have to be constant at compile time. They are evaluated in the order they appear here until one of the expressions has a non-zero value. The text linked to the statement is compiled. The other lines are ignored. The order of segments is fixed. The ‎ELSIF‎ and ‎ELSE‎ segments are optional. The ‎ELSIF‎ segments may occur any number of times.You can use multiple conditional compile operators within the constants ‎<expr>‎.

‎<expr>‎

You can use one or more operators within the constant expression ‎<expr>‎ within the conditional compile pragma ‎{IF}‎ or ‎{ELSIF}‎ .

You can specify expressions and ‎define‎ definitions as “compiler definitions” on the “Build” tab in the Properties dialog of POUs. If you specify ‎define‎ definitions in the properties dialog, then you have to omit the term ‎{define}‎, in contrast to the definition in the implementation code. Moreover, you can specify multiple comma-separated ‎define‎ definitions in the properties dialog.