Re: E/SQL host arrays with defined sizes
Posted in 1998
Tim Friest wrote: > > I would like to use defines for the sizes of some of the arrays in > my E/SQL C code... > > i.e. > > #define COLUMN_WIDTH 18 > > EXEC SQL BEGIN DECLARE; > char column[COLUMN_WIDTH+1]; > EXEC SQL END DECLARE; > > EXEC SQL SELECT column into :column FROM table > WHERE something=something; > > When something like the above is compiled, esqlc generates warnings > like > > esqlc: "????.ec", line ###: Warning -33208: Runtime error is > possible because size of 'column' is unknown. > > but other places I use similar arrays I do not get warnings about > unknown size... > > The reason I want to use the #define instead of the hard coded size > is because I have a column which changed width and I now have to go > to the half dozen places that it is hardcoded with the old size to > fix it to the new size... I would just assume fix it with a > #define so I won't run > into this problem again... > > How would I solve this problem? Tim, the reason esql is complaining is that it gets to look at the code before the C preprocessor gets it to expand the #define statements. I believe it will make no run-time difference because before the compile is complete the array length will be properly defined. However, you don't want this warning to distract you from real compile problems. Have you tried: $define COLUMN_WIDTH 18; or EXEC SQL define COLUMN_WIDTH 18; Page 1-8 of the ESQL Programmer's Manual (7.2) indicates this would be legit. I just tried it (7.14) and had no complaints. +===================================+ | EXEC SQL define COLUMN_WIDTH 18; | | | | EXEC SQL BEGIN DECLARE SECTION; | | char column[COLUMN_WIDTH+1]; | | EXEC SQL END DECLARE SECTION; | | | | main() | | { | | printf("Hello\\n"); | | } | +===================================+ -- -- Jake (Retrospectively realizes there is no future in hindsight) +------------------------------------------------------------+ | The expedient performance of a task with excessive concern | | regarding its duration-to-completion engenders a virtual | | certainty of diminished benefit therefrom. | | -- Benjamin Franklin (but he said it in 3 words) | +------------------------------------------------------------+