This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

C252 and #if statements

I have a header file that will be compiled by multiple different compilers. This being the case, I want to use #if statements to change the compilation flow based on the current compiler. In the Keil compiler case, I want to use the #pragma NOIV to disable vector table generation, so I used the following at the beginning of the file:

#if(__C51__)

/* some comment */
#pragma NOIV

#endif /* end __C51__ */

I received the C252 error about misplaced control lines. Looking at the documentation, blank lines and comment lines should be ignored, so I would expect what I have written to work, since the pre-processor should remove or add the pragma before the compiler is invoked. Is this case, or is it impossible to use control lines with #if statements?

Thanks, Ian.

Parents
  • Oh, there's WAY too much code out there with #ifdef for any compiler ever to stop supporting it. It'll just remain deprecated forever :)

    I try to write new code the new way, though. ("New", as if 1989 were new... There are people writing code younger than the preprocessor statement.)

    In general I like to avoid #if defined() at all. Usually I resolve alternate implementations at link time. That is, I just have two files with two implementations and link in the right one, rather than having one file that's been turned into hash with #if. Or in the case of headers, I just use the header with definitions appropriate for the platform, rather than chaining through every possibility.

    But there's always some bit of code that's just too small to justify pulling out from a module that otherwise identical. #ifdef will never die.

Reply
  • Oh, there's WAY too much code out there with #ifdef for any compiler ever to stop supporting it. It'll just remain deprecated forever :)

    I try to write new code the new way, though. ("New", as if 1989 were new... There are people writing code younger than the preprocessor statement.)

    In general I like to avoid #if defined() at all. Usually I resolve alternate implementations at link time. That is, I just have two files with two implementations and link in the right one, rather than having one file that's been turned into hash with #if. Or in the case of headers, I just use the header with definitions appropriate for the platform, rather than chaining through every possibility.

    But there's always some bit of code that's just too small to justify pulling out from a module that otherwise identical. #ifdef will never die.

Children
No data