Re: ESQL/C Preprocessor
Posted in 1993
David Coburn writes: |> TechInfo # 1068 |> |> Short Description: |> Why can I not use #DEFINES in ESQL/C? |> |> Long Description: |> From mail dated July 27, 1991: |> |> QUESTION: |> ========= |> Why is the following illegal? |> |> #DEFINE x 1024 |> $CHAR sql_cmd[x] |> |> |> ANSWER: |> ======= |> The esql preprocessor looks at the above statement and sees the # sign. |> It thinks that this is a comment and strips it from the program. This |> way it is not defined when it goes through the C compile. To get |> around this problem you can run the program through 'cpp', the C |> preprocessor, which will substitute in the value for the #DEFINE and |> #INCLUDE lines. Then you can use ESQL to compile the program as |> normal. |> |> Basically, what I'm saying is that the #endif will be treated as a comment, |> yeilding the same results as this tech info article discusses. Sorry, Dave, but this is WRONG. The problem has nothing to do with esql/c interpreting # as a comment (why on earth would it do that? # is a 4gl comment). The reason is that esql/c does not preprocess # statements, and when it comes to the $CHAR sql_cmd[x], it cannot resolve that x is a macro, and it considers the statement to be a syntax error. If you compile your sample program without the CHAR declaration, you will find that the #define x 1024 makes it into the resulting .c file quite nicely. Furthermore, if you were to declare your sql_cmd as a non-host variable, it will compile just fine (of course, you would not then be able to use sql_cmd in an sql statement). That would not be the case if esql/c was stripping #define's out as comments. Dave Disclaimer: These opinions are not those of Informix Software, Inc. ************************************************************************** "I look back with some satisfaction on what an idiot I was when I was 25, but when I do that, I'm assuming I'm no longer an idiot." - Andy Rooney