Re: Pro*C & C-precompiler coexistence problem

From: Michael Chiocca <mchiocca_at_oracle.com>
Date: 1996/03/29
Message-ID: <4jh228$ev2_at_inet-nntp-gw-1.us.oracle.com>#1/1


The 1.x version of Pro*C did not recognize preprocessor directives so users were not able to use macros to define constants for use elsewhere..

The 2.x version of Pro*C includes a preprocessor which does allow one to define and use macros in several places.

  1. Type and variable declarations
     #define LENGTH 10
     typedef char asciz[LENGTH];
     asciz ename;
     varchar job[LENGTH];

     Basically, any precompile time evaluable constant
     expression is legal (Pro*C does constant folding).
     The only exception is that constant declarations 
     don't currently work.

     const int length = 10;
     varchar dname[length];
                   ^^^^^^-ILLEGAL

     That should hopefully be solved by 2.2.3.
   

  2. Type and Variable Equivalencing

     exec sql type asciz is string(LENGTH);
     char dname[LENGTH];
     exec sql var dname is string(LENGTH);

     However, Pro*C does not currently allow arbitrary
     constant expressions, only a numeric literal or
     simple macro whose definition is a numeric literal.

Pro*C 2.x does NOT allow macros to be used everywhere. For example..

  1. DECLARE TABLE Statements
      exec sql declare t table (column varchar2(LENGTH));
                                        ILLEGAL-^^^^^^

      This restriction applies to DDL as also so you cannot
      CREATE a table in this way either.

  2. Inside SQL statements (e.g. WHERE clauses)

      #define JOB 'PRESIDENT';
      exec sql select ename into :ename
                 from emp where job = JOB;
                                      ^^^-ILLEGAL

In short, macros are OK when processing C (i.e. type and variable declarations, bind variable expressions, etc) but NOT when processing SQL.

Hope that helps to clarify some things regarding macro usage. Refer to the 2.x manuals for complete details regarding Pro*C's preprocessor and proper uses of macros.

Michael J Chiocca
Oracle Corporation Received on Fri Mar 29 1996 - 00:00:00 CET

Original text of this message