Re: Pro*C / C++ ??

From: Janne Paatero <paatero_at_tele.nokia.fi>
Date: 9 Jan 93 16:48:47 GMT
Message-ID: <PAATERO.93Jan9184847_at_olorin.tele.nokia.fi>


(I'm afraid that I have messed up with my previous posting. If not, my apologies.)

Hello Netland and especially David Hudek,

In article <145384_at_lll-winken.LLNL.GOV> David Hudek had questions about Oracle's Pro*C precompiler and C++.

> Is there any reason why the output of Pro*C couldn't then be
> run through Sun's C++ compiler and produce good executables? (since the
> C++ compiler can obviously handle straight C code).

The most important experience of mine is: Yes, they can be integrated and the executables work. (At least in my case --- I've been using Oracle version 6, Pro*C precompiler version 1.3 and C++ version 2.1 in HP risc boxes, Tandem S2 systems and MIPS risc machines.)

> The only potential problem I can think of at the moment from a programming
> standpoint is how function declarations are handled...

This is true. The workaround that has to be done is to modify the prototypes of Oracle system calls. As very well known, Pro*C output has function declarations like

        extern void sqlxxx();

The trick that changes these to be compliant with C++ is to change the declaration to varparam (three dots inside parenthesis) and typesafe C linkage. So the previous declaration should be modified to something like

	#ifdef __cplusplus
	extern "C" {
	#endif /* __cplusplus */

	extern void sqlxxx(...);

	#ifdef __cplusplus
	}
	#endif /* __cplusplus */

The #ifdefs in the previous example are there to make the modified code also compliant with ANSI standard C.

Luckily this workaround task can be easily automated. I'm using the following shell && nawk script which I hereby release to public, free of charge, with absolutely no warranty of any kind, under GNU general public licence.

The script takes the precompiled file as argument, locates the Oracle system call prototypes and makes the modifications described above to them. The original file is saved with a suffix .old.

Hope this helps,

        janne

/******************************************************************************
 Janne Paatero           * "Maybe a db wheenie in Nokia Telecommunications Oy"
 paatero_at_tele.nokia.fi   * "but still speaking only for myself."
 paatero_at_ntc.nokia.com *
******************************************************************************/

---clipeti--clap---clipeti--clap---clipeti--clap---clipeti--clap---clipeti--

#!/bin/sh
#
# A simple shell and nawk script to repair output of Pro*C precompiler of
# Oracle Inc. to make it compliant with C++.
#
# Copyright (C) Janne Paatero, 1992.
# You may use and redistribute this under GNU general public licence.
#

if [ $# -ne 1 ]
then

	echo "You should give the name of the file to be repaired."
	exit 1

fi

awk 'BEGIN {

# Set up global variables, types and parameters.

	first = 1
	last = 0

}

function beginToken() {

	printf("/*******************************************************/\n")
	printf("/***          Repaired for C++ by PCCrepair          ***/\n")
	printf("/***          PCCrepair script by J.Paatero          ***/\n")
	printf("/*******************************************************/\n")
        printf("#ifdef __cplusplus\n")
	printf("extern \"C\" {\n")
	printf("#endif /* __cplusplus */\n")

}

function endToken() {

        printf("#ifdef __cplusplus\n")
	printf("}\n")
	printf("#endif /* __cplusplus */\n")

}

{

	while ($1 == "extern" && $2 == "void" && $3 ~ /^sql/ && $3 ~ /\(\);$/){
	  if (first) {
	    first = 0
	    last = 1
	    beginToken()
	  }
	  sub(/\(\);$/, "(...);")
	  print
	  getline
	}
	if (last) {
	  last = 0
	  endToken()
	}

 print
}' $1 >/tmp/PCCrepair.$$
mv -f $1 $1.old
cp /tmp/PCCrepair.$$ $1
rm /tmp/PCCrepair.$$
---clipeti--clap---clipeti--clap---clipeti--clap---clipeti--clap---clipeti-- Received on Sat Jan 09 1993 - 17:48:47 CET

Original text of this message