Re: C++ and Informix
Posted in 1997
Nick Nobbe a 'crit dans le message <628qi0$2s2@cssun.mathcs.emory.edu>... >On Fri, 17 Oct 1997, Vijay Kammila wrote: >> Hi, >> I have some programs written in C using INFORMIX-ESQL Version 7.22.UC1. >> If I want to change them to C++, do I need a different esql that >> supports C++ or is it just that the files should have different >> .extensions (like .C instead of .c and .???? instead of .ec) and >> different compiler options (instead of esql XXX.c XXXX.ec)? >> > Vijay, > I remember Jonathan Leffler gave a brief talk on how to do c++ with > esqlc at the WAIUG forum in 1996. You will probably find more info > (the correct kind) at the IIUG cdi archives site at www.iiug.org and > and possibly in one of our newsletters at www.iiug.org/~waiug . > And I think you have to mess with your includes also. There are also other language features that ESQL/C does not support natively, even using ANSI C with strong prototyping. I simply solved the problem by using dummy declarations for ESQL/C enclosed between #if 0 ... #endif pairs, in addition to strong type declarations. A good writing of it is for example: #define ESQLC_DUMMY 0 ... int foo(char *bar, int foobar) #if ESQLC_DUMMY EXEC SQL BEGIN DECLARE SECTION; char *bar; int foobar; EXEC SQL END DECLARE SECTION; #endif { ... } You can use such dummy declarations that ESQL/C understand, and still benefit of strong typing of ANSI C or C++. Sometimes, you'll have to use simplified declarations of your typedefs, and structure declarations. ESQL/C will still generate the correct code, provided types are convertible, because all the generated C statements will reference your real declarations, not those between the #if 0... #endif pairs which won't be compiled. Such constructs allow easier management of calling conventions, memory models for arrays and pointers, C or C++ features, strong datatypes, ... More, you do not need to declare all members of your structures in dummy declarations, but just those data members that you need to reference in your ESQL/C statements, i.e. structure pointers, structure names, char[] and numeric datatypes, and so on... If it causes to much work, just declare additionnal simple C working variables to run with ESQL/C statements, and make appropriate copies.