2 #if, 3 #else, Simpliq – ElmoMC SimplIQ Software Manual User Manual
Page 79

SimplIQ
Software Manual
Program Development and Execution
MAN-SIMSW (Ver. 1.4)
6-17
6.4.1.2 #if
The #if directive checks the conditional expression, as it does in the C language. If the
specified constant expression following the #if has a non-zero value, it directs the Compiler
to continue processing statements up to the next #endif, #else or #elseif. Afterwards, it
skips to the statement following the #endif directive. If the conditional expression has a
zero value, #if directs the Compiler to skip to the next #endif, #else or #elseif directive.
Syntax:
#if constant-expression
The constant-expression is either an integer or a float constant expression.
Each #if directive in a source file must be matched with a closing #endif directive;
otherwise, an error message is generated.
The #if, #elseif, #else and #endif directives can be nested in the text portions of other #if
directives. Each nested #else, #elseif or #endif directive belongs to the closest preceding #if
directive.
The #if directive must contain a constant-expression, which is evaluated to a single value;
otherwise it causes an error.
Example:
#if MAX_LEN > 10
#define REDUCE_MAX_LEN 10
#endif
In this example, REDUCE_MAX_LEN will be defined as the integer constant 10 only if MAX_LEN
is greater than 10; otherwise, it will not be defined at all.
6.4.1.3 #else
The #else directive, as in C, marks an optional clause of a conditional-compilation block
defined by an #ifdef or #if directive.
Syntax:
#else
The #else directive must be the last directive before the #endif directive. Only a single #else
directive is allowed. The #else directive contains no conditions.
Example:
#if MAX_LEN > 10
#define REDUCE_MAX_LEN 10
#else
#define REDUCE_MAX_LEN 5
#endif
In this example, REDUCE_MAX_LEN will be defined as the integer constant 10 only if MAX_LEN
is greater than 10; otherwise, it will be defined as the integer constant 5.