Postgres Plus Advanced Server Oracle Compatibility Developer's Guide : 13.1 C-preprocessor Directives

Previous PageTable Of ContentsNext Page

Postgres Plus Advanced Server Oracle Compatibility Developer's Guide

 

13.1 C-preprocessor Directives

The ECPGPlus C-preprocessor enforces two behaviors that are dependent on the mode in which you invoke ECPGPlus:

      PROC mode

      ● non-PROC mode

Compiling in PROC mode

In PROC mode, ECPGPlus allows you to:

    ● Declare host variables outside of an EXEC SQL BEGIN/END DECLARE SECTION.

    ● Use any C variable as a host variable as long as it is of a data type compatible with ECPG.

When you invoke ECPGPlus in PROC mode (by including the -C PROC keywords), the ECPG compiler honors the following C-preprocessor directives:

      #include

      #if expression

      #ifdef symbolName

      #ifndef symbolName

      #else

      #elif expression

      #endif

      #define symbolName expansion
      #define symbolName([macro arguments]) expansion

      #undef symbolName

      #defined(symbolName)

Pre-processor directives are used to effect or direct the code that is received by the compiler. For example, using the following code sample:

      #if HAVE_LONG_LONG == 1

      #define BALANCE_TYPE long long

      #else

      #define BALANCE_TYPE double

      #endif

      ...

      BALANCE_TYPE customerBalance;

If you invoke ECPGPlus with the following command-line arguments:

      ecpg –C PROC –DHAVE_LONG_LONG=1

ECPGPlus will copy the entire fragment (without change) to the output file, but will only send the following tokens to the ECPG parser:

      long long customerBalance;

If you invoke ECPGPlus with the following command-line arguments:

      ecpg –C PROC –DHAVE_LONG_LONG=0

The ECPG parser will receive the following tokens:

      double customerBalance;

If your code uses preprocessor directives to filter the code that is sent to the compiler, the complete code is retained in the original code, while the ECPG parser sees only the processed token stream.

If you do not include the -C PROC command-line option:

    ● C preprocessor directives are copied to the output file without change.

    ● You must declare the type and name of each C variable that you intend to use as a host variable within an EXEC SQL BEGIN/END DECLARE section.

When invoked in non-PROC mode, ECPG implements the behavior described in the PostgreSQL Core documentation, available at:

Previous PageTable Of ContentsNext Page