The ifdef, ifndef, elif, else, and endif directives

The Informix® ESQL/C preprocessor supports the following directives for conditional compilation:
ifdef
Tests a name and executes subsequent statements if define has created the name.
ifndef
Tests a name and executes subsequent statements if define has not created the name.
elif
Begins an alternative section to an ifdef or ifndef condition and checks for the presence of another define. It is shorthand for “else if define ”.
else
Begins an alternative section to an ifdef or ifndef condition.
endif
Closes an ifdef or ifndef condition.
In the following example, the BEGIN WORK statement compiles only if you previously defined the name USETRANSACTIONS with a define directive:
EXEC SQL ifdef USETRANSACTIONS;
EXEC SQL begin work;
EXEC SQL endif;
The following example illustrates the use of the elif statement. This sample code will print “USETRANSACTIONS defined”.
EXEC SQL define USETRANSACTIONS;
   
⋮

   EXEC SQL ifndef USETRANSACTIONS;
      printf(“USETRANSACTIONS not defined”);
   EXEC SQL elif USETRANSACTIONS;
      printf(“USETRANSACTIONS defined”);
   EXEC SQL endif;

The Informix ESQL/C preprocessor does not support a general if directive; it supports only the ifdef and ifndef statements that test whether a name was defined with define.

The Informix ESQL/C preprocessor processes conditional compilation definitions in stage 1 of the preprocessing.


Copyright© 2019 HCL Technologies Limited