Run the C preprocessor before the ESQL/C preprocessor

The compilation of the HCL OneDB™ ESQL/C source file can follow either the default order, where the HCL OneDB ESQL/C preprocessor runs first on the source file, or it can allow the C preprocessor to run on the source file before the HCL OneDB ESQL/C preprocessor.

The default sequence of compilation for the HCL OneDB ESQL/C source file is as follows:
  1. The HCL OneDB ESQL/C preprocessor performs the following steps to create a .c file from the HCL OneDB ESQL/C source file:
    • Incorporates HCL OneDB ESQL/C header files into the source file when it processes all include directives ($include and EXEC SQL include statements)
    • Creates or removes compile-time definitions when it processes all define ($define and EXEC SQL define) and undef ($undef and EXEC SQL undef) directives
    • Processes any conditional compilation directives (ifdef, ifndef, else, elif, endif) and translates embedded SQL statements to HCL OneDB ESQL/C function calls and special data structures
  2. The C preprocessor takes the following actions:
    • Incorporates C header files into the source file when it processes all C include directives (#include)
    • Creates or removes compile-time definitions when it processes all C language define (#define) and undef (#undef) directives
    • Processes C conditional compilation directives (#ifdef, #ifndef, #else, #elif, #endif)
  3. The C compiler, assembler, and linker work in the usual way, as they do for a C source file, translating the C code file into an executable program.

This default order of compilation is restrictive because you cannot use #defines or typedefs defined in C system header files or custom C header files to define HCL OneDB ESQL/C host variables and constants, nor can you use them for conditional compilation of HCL OneDB ESQL/C code. With the default order of compilation, C header files do not get included into the HCL OneDB ESQL/C source code until after the HCL OneDB ESQL/C preprocessor has run, making these definitions unavailable to the HCL OneDB ESQL/C preprocessor.