The FESQLC compiler supports ESQL/C preprocessor directives. This allows you to include other ESQL/C files, define macros that can be used later in the code and use ifdef conditional directives to compile only some part of the code, as you can do with the C preprocessor (cpp):
EXEC SQL include "myheader.h"; EXEC SQL define LEN 15; EXEC SQL ifdef DEBUG; ... EXEC SQL endif;
Standard C preprocessing takes effect after ESQL/C preprocessing, during the C compilation step. In order to include system header files such as stdio.h, you must use the standard C #include directive. If C macros are defined, you must use standard C #ifdef directives. FESQLC will ignore any C macro definitions during the ESQL/C preprocessing step.
The include directive allows you to include other files into your FESQLC programs. You must use the FESQLC include directive if the file contains embedded SQL statements or other FESQLC statements.
The file will be read into the program at the location of the include directive. Use the keywords EXEC SQL (preferred ANSI standard) or the $ symbol to precede the directive. Specify the exact name, including any extension, of the file:
EXEC SQL include "def_constants.h"; EXEC SQL include "/prog/def_constants.h";
If the filename includes the path, you must enclose the filename in quotation marks. Otherwise, you may omit the quotation marks, but FESQLC will convert the filename to lowercase. If you omit the path, FESQLC will search the preprocessor path for the file.
To avoid the need for recompilation if a file location changes, omit the path from the filename and use the -I FESQLC compiler option to specify the path:
fesqlc -I ./myincludes prog1.ec
Note: Use the standard C #include directive to include C system header files.
The FESQLC define directive allows you to create simple macros that are available only to the FESQLC preprocessor. The FESQLC preprocessor, rather than the C preprocessor, processes this directive.
Use the keywords EXEC SQL (preferred ANSI standard) or the $ symbol to precede the directive:
EXEC SQL define CHECKED; -- macro without a value EXEC SQL define LEN 15; -- macro with an integer value of 15 EXEC SQL define NAME "scott"; -- macro with a string value
The scope of the macro is from the location of the define directive until the end of the file, or until the macro is removed. The FESQLC undef directive allows you to remove the macro:
EXEC SQL undef LEN;
You can use the FESQLC compiler options -ED and -EU to override these FESQLC macro definitions.
Note: C macros are defined and undefined using the #define and #undef C preprocessor directives in your source code, or the -D and -U FESQLC preprocessor options.
Macros can be used in conjunction with other FESQLC preprocessor directives to control conditional processing of a file.
FESQLC provides directives to conditionally compile a program. The directives test whether a macro has been created with an FESQLC define directive or the -ED FESQLC compiler option, and then process the file accordingly.
Use the keywords EXEC SQL (preferred ANSI standard) or the $ symbol to precede the directive:
EXEC SQL ifdef CHECKED; EXEC SQL DELETE FROM cust_temp; /* executed when CHECKED is defined */ EXEC SQL endif;EXEC SQL ifdef CHECKED; EXEC SQL DELETE FROM cust_temp; EXEC SQL else; /* if CHECKED is not defined */ printf("no delete, CHECKED is not defined"); EXEC SQL endif;EXEC SQL ifdef CHECKED; EXEC SQL DELETE FROM cust_temp; EXEC SQL elif PROBLEMS; /* if CHECKED not defined and PROBLEMS defined */ printf("no delete, PROBLEMS is defined"); EXEC SQL endif;
Note: There is no equivalent to the "if" C directive in FESQLC; the preprocessor supports only the ifdef and ifndef statements that test for the existence of a macro.
If your program uses both FESQLC macros and C macros, you can combine the -D and -ED preprocessor options in the same command line. The following lines in the FESQLC program prog.ec has two blocks of preprocessing directives. The first block uses FESQLC syntax and the second block uses the standard C syntax:
EXEC SQL ifdef CHECKED; printf("CHECKED is defined"); EXEC SQL else; printf("CHECKED is not defined"); EXEC SQL endif; #ifdef MAXLEN printf("MAXLEN is defined"); #else printf("MAXLEN is not defined"); #endif
If you combine FESQLC -ED and -D command line options like this:
fesqlc -ED CHECKED -D MAXLEN prog.ec
FESQLC will create the FESQLC macro CHECKED, and will create the C macro MAXLEN.
When the program is run, the following lines would be executed:
printf("CHECKED is defined"); printf("MAXLEN is defined");