Re: Pro*C Variables and Define Tokens

From: Andy Finkenstadt <andy_at_homebase.vistachrome.com>
Date: Wed, 23 Sep 1992 08:13:11 GMT
Message-ID: <1992Sep23.081311.27977_at_homebase.vistachrome.com>


gerette_at_cbnewsb.cb.att.com (marianne.g.pittorino) writes:
>I am having trouble declaring Pro*C variables using #define tokens. In my
>(UNIX) application, we have an include header file that has #define tokens
>for all our data elements. When declaring a 'C' or database variable, we
>always use the #define token. For example, if a customer name variable were
>needed, we code:
>
> char custname[CUSTNAME_SZ + 1]; /* add one for NULL byte */
>
>This helps us easily maintain the application if data elements should change
>size. I have found, however, that the Pro*C compiler (pcc) reports an error
>when I use this construct:
>
>Precompiling x.pc
> 20 VARCHAR custname[CUSTNAME_SZ + 1];
> 20 ........................^
> PCC-S-0018: Expected "<unsigned_integer>", but found "CUSTNAME_SZ" at
> line 20 in file x.pc
>Marianne

The problem is, as you outlined in the part I just deleted by accident :), is that the Pro*C compiler does NOT understand #define #include and so on. I attempted to do exactly as you did 2 years ago, called Oracle, and was told there's no workaround, sorry, click. (Not that abrupt, but I think the guy had a bad day or something.)

Well, there is a work-around. In fact I can think of two.

This is off the top of my head (I know more now than I did then) and untested - but it SHOULD work. Part will depend on if pcc will understand "15+1" as <unsigned_integer>.

ONE
===

Invoke the C pre-processor (usually cc -E or cpp or cc -P, if you have installed perl it'll tell you how if you read it as it figures out your system) on your .pc program and save the output in another file. Now Pro*C pre-compile the output from the first step, obtaining a .c file ready for standard compilation. Compile THAT and you might be set.

TWO
===

If that doesn't work - or if you really want a cleaner solution, use the m4(1) program to do macro substitution. This has some interesting side effects on tokens like INDEX and the like. For example:

in 'database_structure.mi' put:

	define(CUSTNAME_SZ,15)
	define(other_sz,10)
	...

Now in your .m4 source code put:
	char custname[CUSTNAME_SZ+1];

Now as part of your Pro*C compilation do this:
	#	pc - compile a Pro*C program whose source is in $1.m4
	# convert database constants
	m4 database_structure.mi  $1.m4 >$1.pc
	# run it through Pro*C
	pcc $1.pc (substitute your oracle parameters, userid, sqlcheck, etc)
	# compile it
	cc -o $1 -O $1.c
	# show sizes before, during and after unnecessary info stripping
	ls -l $1
	# strip symbols
	strip $1
	ls -l $1
	# remove all comment sections
	mcs -d $1
	ls -l $1
	# show incore, data and stack sizes
	size $1


-- 
Andrew Finkenstadt       | Vista-Chrome, Inc.   |           andy_at_GEnie
GEnie Unix Sysop/Manager | The Printing House   |    NIC Handle: AF136
+1 904 222 2639 home     | 1600 Capital Cir SW  |   ...!uunet!rde!andy
+1 904 575 0189 work     | Tallahassee FL 32310 | andy_at_vistachrome.com

     The game of love is never called off on account of darkness.
Received on Wed Sep 23 1992 - 10:13:11 CEST

Original text of this message