Re: Pro*C - nice coding techniques

From: Rudolf Jan Heijink <heijink_at_pttrnl.nl>
Date: 14 Feb 92 08:08:49 GMT
Message-ID: <heijink.698054929_at_freyr>


matt_at_cernvax.cern.ch (matthew tarrant) writes:

>In <1992Feb5.125602.15658_at_uqvax.cc.uq.oz.au> ccdavid_at_uqvax.cc.uq.oz.au writes:
>[stuff deleted]
>>I don't like using explicit declarations e.g. char str[50];
>>because magic nubers (i.e. 50) suk, esp. when they are likely to
>>change often. I need to #define magic numbers for use in the code
>>*and* have them hard coded in the SQL declaration. This becomes
>>awkward when there are 200+ variables. Also, it doesn't lend itself
>>to the use of structures very well (my main gripe).
>[more stuff deleted]
 

>To resolve those #defined constants, run the .pc file through
>the C preprocessor first. Sample follows:
 

>$(CC) -E -I/user/lepdev/dev/include $< | grep -v '#' > $*_temp.pc
>$(PCC) $(PCCFLAGS) iname=$*_temp.pc oname=$*.c
>$(RM) $*_temp.pc
>$(CC) $(CFLAGS) -I/user/lepdev/dev/include -c $*.c
 

>The first line is the interesting one: it runs the pc
>files through the C preprocessor (-E), greps to
>remove any lines starting with a '#' added by it,
>(which would otherwise screw up the next pass) and
>stores the results.
 

>It works for me!

For a long period I used this method too. I abandoned it now because of some serious problems:

  • Interference may occur with Oracle reserved words. An eample that will occurr definitely is NULL. NULL is an unavoidable macro in C and it is used as keyword in Oracle.
  • The behaviour of preprocessors is a little bit unpredictable. Using gcc it worked file, but using the vcc compiler, the preprocessor tries to interpret constructs like 'ABC'. The preprocessor thinks this is a multi-byte character.

Therefore I wrote a flex program that scans for constructs like

#define X Y

and

#define Y 10

it replaces

Z[X] by Z[10]

This is much more restricted and therefore much more safe.

Rudolf Jan Heijink

--
Rudolf J. Heijink               phone : +31 70 332 5709
PTT Research POB 421            fax   : +31 70 332 6477
2260 AK  Leidchsendam  E-Mail: R.J.Heijink_at_research.ptt.nl (internet)
Netherlands                     ...!hp4nl!dnlunx!heijink (UUCP)
Received on Fri Feb 14 1992 - 09:08:49 CET

Original text of this message