ESQL/C preprocessor question
Posted in 2000
Topics: Connectivity: ESQL/C, 4GL & Embedded SQL
My apologies if this is in a manual somewhere, I just can't find it. We're currently using Informix 7.3x, and I'm trying to get a library module written. I have the following in a header file (header_file_1): #define MAX_ABA_LEN 9 #define MAX_NACCT_LEN 18 and the following in another header file (header_file_2.h): #include "header_file_1.h" struct _my_struct { char aba[ MAX_ABA_LEN+1 ]; char nacct[ MAX_NACCT_LEN+1 ]; }; Now, in the code, I declare: EXEC SQL BEGIN DECLARE SECTION; EXEC SQL include "header_file_2"; EXEC SQL END DECLARE SECTION; ... cool nifty code, etc. ... EXEC SQL BEGIN DECLARE SECTION; struct _my_struct rec; EXEC SQL END DECLARE SECTION; Then, I use this in EXEC SQL calls later, etc...The problem is that esql doesn't seem to be able to figure out how big the structure elements are (and I have bizarre complication problems if the #defines are directly in the file that is included with EXEC SQL include), so when I try to use them in the program later it complains: esqlc: "micrParse.ec", line 322: Warning -33208: Runtime error is possible because size of 'rec.aba' is unknown. I believe this is because I am not doing EXEC SQL define MAX_ABA_LEN 9. I can't do this however, because those #defines/structures are used in non-esql programs. Can anyone tell me how I can get esql to recognize those #defines? (Hopefully I'm not missing something blindingly obvious, although it wouldn't be the first time) Thanks! Tavis Elliott
Hi Tavis, Tavis Elliott schrieb: > My apologies if this is in a manual somewhere, I just can't find it. We're > currently using Informix 7.3x, and I'm trying to get a library module > written. I have the following in a header file (header_file_1): > > #define MAX_ABA_LEN 9 > #define MAX_NACCT_LEN 18 > > and the following in another header file (header_file_2.h): > > #include "header_file_1.h" > > struct _my_struct { > char aba[ MAX_ABA_LEN+1 ]; > char nacct[ MAX_NACCT_LEN+1 ]; > }; > You have to define the struct konstruction within separate SQL-declare sections. Perhaps like this: $struct _my_struct { char aba[ MAX_ABA_LEN+1 ]; char nacct[ MAX_NACCT_LEN+1 ]; }; or this EXEC SQL BEGIN DECLARE SECTION; struct _my_struct { char aba[ MAX_ABA_LEN+1 ]; char nacct[ MAX_NACCT_LEN+1 ]; }; EXEC SQL END DECLARE SECTION; HTH Dirk > > Now, in the code, I declare: > > EXEC SQL BEGIN DECLARE SECTION; > EXEC SQL include "header_file_2"; > EXEC SQL END DECLARE SECTION; > > ... cool nifty code, etc. ... > > EXEC SQL BEGIN DECLARE SECTION; > struct _my_struct rec; > EXEC SQL END DECLARE SECTION; > > Then, I use this in EXEC SQL calls later, etc...The problem is that esql > doesn't seem to be able to figure out how big the structure elements are > (and I have bizarre complication problems if the #defines are directly in > the file that is included with EXEC SQL include), so when I try to use them > in the program later it complains: > > esqlc: "micrParse.ec", line 322: Warning -33208: Runtime error is possible > because size of 'rec.aba' is unknown. > > I believe this is because I am not doing EXEC SQL define MAX_ABA_LEN 9. I > can't do this however, because those #defines/structures are used in > non-esql programs. > > Can anyone tell me how I can get esql to recognize those #defines? > (Hopefully I'm not missing something blindingly obvious, although it > wouldn't be the first time) > Thanks! > > Tavis Elliott
The problem is that the esql preprocessor does not run cpp until AFTER the .c code has been generated and that is too late to know the values of the #defines. You have to change the #defines to "EXEC SQL DEFINE..." statements which may cause you grief in your multilevel include since the EXEC SQL DEFINEs will be within the EXEC SQL BEGIN DECLARE SECTION, I just don't know. But if that gives you trouble just move the nested include to the outer source file before the DECLARE SECTION. Art S. Kagel Tavis Elliott wrote: > > My apologies if this is in a manual somewhere, I just can't find it. We're > currently using Informix 7.3x, and I'm trying to get a library module > written. I have the following in a header file (header_file_1): > > #define MAX_ABA_LEN 9 > #define MAX_NACCT_LEN 18 > > and the following in another header file (header_file_2.h): > > #include "header_file_1.h" > > struct _my_struct { > char aba[ MAX_ABA_LEN+1 ]; > char nacct[ MAX_NACCT_LEN+1 ]; > }; > > Now, in the code, I declare: > > EXEC SQL BEGIN DECLARE SECTION; > EXEC SQL include "header_file_2"; > EXEC SQL END DECLARE SECTION; > > ... cool nifty code, etc. ... > > EXEC SQL BEGIN DECLARE SECTION; > struct _my_struct rec; > EXEC SQL END DECLARE SECTION; > > Then, I use this in EXEC SQL calls later, etc...The problem is that esql > doesn't seem to be able to figure out how big the structure elements are > (and I have bizarre complication problems if the #defines are directly in > the file that is included with EXEC SQL include), so when I try to use them > in the program later it complains: > > esqlc: "micrParse.ec", line 322: Warning -33208: Runtime error is possible > because size of 'rec.aba' is unknown. > > I believe this is because I am not doing EXEC SQL define MAX_ABA_LEN 9. I > can't do this however, because those #defines/structures are used in > non-esql programs. > > Can anyone tell me how I can get esql to recognize those #defines? > (Hopefully I'm not missing something blindingly obvious, although it > wouldn't be the first time) > Thanks! > > Tavis Elliott
My version of esql (7.23.UC5) allows me to choose whether to run cpp or the esql preprocessor first. Naming the file with a .ecp extension causes this to happen. This makes the problem 'different', rather than solving it completely. Andy. In article <3912F47F.C4B00F34@bloomberg.net>, "Art S. Kagel" <kagel@bloomberg.net> writes >The problem is that the esql preprocessor does not run cpp until AFTER the >.c code has been generated and that is too late to know the values of the >#defines. You have to change the #defines to "EXEC SQL DEFINE..." >statements which may cause you grief in your multilevel include since the >EXEC SQL DEFINEs will be within the EXEC SQL BEGIN DECLARE SECTION, I just >don't know. But if that gives you trouble just move the nested include to >the outer source file before the DECLARE SECTION. > >Art S. Kagel > >Tavis Elliott wrote: >> >> My apologies if this is in a manual somewhere, I just can't find it. We're >> currently using Informix 7.3x, and I'm trying to get a library module >> written. I have the following in a header file (header_file_1): >> >> #define MAX_ABA_LEN 9 >> #define MAX_NACCT_LEN 18 >> >> and the following in another header file (header_file_2.h): >> >> #include "header_file_1.h" >> >> struct _my_struct { >> char aba[ MAX_ABA_LEN+1 ]; >> char nacct[ MAX_NACCT_LEN+1 ]; >> }; >> >> Now, in the code, I declare: >> >> EXEC SQL BEGIN DECLARE SECTION; >> EXEC SQL include "header_file_2"; >> EXEC SQL END DECLARE SECTION; >> >> ... cool nifty code, etc. ... >> >> EXEC SQL BEGIN DECLARE SECTION; >> struct _my_struct rec; >> EXEC SQL END DECLARE SECTION; >> >> Then, I use this in EXEC SQL calls later, etc...The problem is that esql >> doesn't seem to be able to figure out how big the structure elements are >> (and I have bizarre complication problems if the #defines are directly in >> the file that is included with EXEC SQL include), so when I try to use them >> in the program later it complains: >> >> esqlc: "micrParse.ec", line 322: Warning -33208: Runtime error is possible >> because size of 'rec.aba' is unknown. >> >> I believe this is because I am not doing EXEC SQL define MAX_ABA_LEN 9. I >> can't do this however, because those #defines/structures are used in >> non-esql programs. >> >> Can anyone tell me how I can get esql to recognize those #defines? >> (Hopefully I'm not missing something blindingly obvious, although it >> wouldn't be the first time) >> Thanks! >> >> Tavis Elliott Andrew Lennard andy@kontron.demon.co.uk
Andy Lennard wrote: > > My version of esql (7.23.UC5) allows me to choose whether to run cpp or > the esql preprocessor first. Naming the file with a .ecp extension > causes this to happen. > > This makes the problem 'different', rather than solving it completely. You are correct, Andy, and I had considered mentioning that but I personally prefer the PURE ESQL solution and so hesitated to mention it. Truth is the -cp option (ESQL 9.xx) or naming files .ecpp does accomplish this. Art S. Kagel > Andy. > > In article <3912F47F.C4B00F34@bloomberg.net>, "Art S. Kagel" > <kagel@bloomberg.net> writes > >The problem is that the esql preprocessor does not run cpp until AFTER the > >.c code has been generated and that is too late to know the values of the > >#defines. You have to change the #defines to "EXEC SQL DEFINE..." > >statements which may cause you grief in your multilevel include since the > >EXEC SQL DEFINEs will be within the EXEC SQL BEGIN DECLARE SECTION, I just > >don't know. But if that gives you trouble just move the nested include to > >the outer source file before the DECLARE SECTION. > > > >Art S. Kagel > > > >Tavis Elliott wrote: > >> > >> My apologies if this is in a manual somewhere, I just can't find it. We're > >> currently using Informix 7.3x, and I'm trying to get a library module > >> written. I have the following in a header file (header_file_1): > >> > >> #define MAX_ABA_LEN 9 > >> #define MAX_NACCT_LEN 18 > >> > >> and the following in another header file (header_file_2.h): > >> > >> #include "header_file_1.h" > >> > >> struct _my_struct { > >> char aba[ MAX_ABA_LEN+1 ]; > >> char nacct[ MAX_NACCT_LEN+1 ]; > >> }; > >> > >> Now, in the code, I declare: > >> > >> EXEC SQL BEGIN DECLARE SECTION; > >> EXEC SQL include "header_file_2"; > >> EXEC SQL END DECLARE SECTION; > >> > >> ... cool nifty code, etc. ... > >> > >> EXEC SQL BEGIN DECLARE SECTION; > >> struct _my_struct rec; > >> EXEC SQL END DECLARE SECTION; > >> > >> Then, I use this in EXEC SQL calls later, etc...The problem is that esql > >> doesn't seem to be able to figure out how big the structure elements are > >> (and I have bizarre complication problems if the #defines are directly in > >> the file that is included with EXEC SQL include), so when I try to use them > >> in the program later it complains: > >> > >> esqlc: "micrParse.ec", line 322: Warning -33208: Runtime error is possible > >> because size of 'rec.aba' is unknown. > >> > >> I believe this is because I am not doing EXEC SQL define MAX_ABA_LEN 9. I > >> can't do this however, because those #defines/structures are used in > >> non-esql programs. > >> > >> Can anyone tell me how I can get esql to recognize those #defines? > >> (Hopefully I'm not missing something blindingly obvious, although it > >> wouldn't be the first time) > >> Thanks! > >> > >> Tavis Elliott > > Andrew Lennard andy@kontron.demon.co.uk