locked
Incorrect preprocessor output with /P option RRS feed

  • Question

  • If I use the /P option to produce a preprocessed .i file from the code at the bottom of this post, the line using the macro expands to

    int x = --20;

    If that is truly the expansion that the compiler is using then obviously a compilation error should occur when the /P option is not used and the code is compiled all the way to a .obj file.  Since no error is occurring, however, then obviously either the .i file does not reflect the real preprocessed output or the compiler itself is broken.  I realize that good programming practice dictates that in most cases a macro replacement list should be parenthesized if it consists of more than a single token and that individual arguments should also be parenthesized in that replacement list, but that is not my point here.  I have seen this inconsistent behavior in all Microsoft compilers since the 1980s and I'm just wondering if anyone knows the reason why it hasn't been fixed, or if there is some other option (other than using a different preprocessor/compiler) that produces consistent results (or maybe I'm just missing something myself).

    Thanks,
    Ray

    #define negate(x) -x

    int main(void)
    {
       int x = -negate(20);

       return 0;
    }

      

    Friday, July 5, 2013 12:13 AM

Answers

All replies