Define and undefine definitions while preprocessing

You can use the -ED and -EU options to create or remove definitions during Informix® ESQL/C preprocessing.

To create a global definition, use one of the following forms of the -ED option:
  • Use the -EDname syntax to define a Boolean symbol, as follows:
    esql -EDENABLE_CODE define_ex.ec
  • Use the -EDname=value syntax to define an integer constant, as follows:
    esql -EDMAXLENGTH=10 demo1.ec

The -EDname is equivalent to the define preprocessor directive ($define or EXEC SQL define) with name at the top of your Informix ESQL/C program.

To remove or undefine a definition globally for the entire source file, use the following syntax for the -EU option:
-EUname

The -EU option has a global effect over the whole file, regardless of other define directives for name.

Restriction: Do not put a space between ED or EU and the symbol name.

As with the define and undef statements, the Informix ESQL/C preprocessor processes the -ED and -EU options in stage 1 of preprocessing (before it preprocesses the code in your source file).

The following figure shows a code fragment that uses conditional compilation (the ifdef and ifndef directives).
Figure 1: ESQL/C excerpt that uses ifdef, ifndef, and endif
/* define_ex.ec */
#include <stdio.h>
EXEC SQL include sqlca;
EXEC SQL define ENABLE_CODE;

main()
{
⋮

EXEC SQL ifdef ENABLE_CODE;
printf("First block enabled");
EXEC SQL endif ENABLE_CODE;
⋮

EXEC SQL ifndef ENABLE_CODE;
EXEC SQL define ENABLE_CODE;
EXEC SQL endif ENABLE_CODE;
⋮

EXEC SQL ifdef ENABLE_CODE;
printf("Second block enabled");
EXEC SQL endif ENABLE_CODE;
}
For the code fragment shown in ESQL/C excerpt that uses ifdef, ifndef, and endif, the following esql command line does not generate code because the command line undefines the ENABLE_CODE definition for the entire source file:
esql -EUENABLE_CODE define_ex.ec