Preprocessor equality test, is this standard?

c, c-preprocessor

Solution

#if TESTING==HOST

If `TESTING` is not defined, then

it is equivalent to:

#if 0==HOST

From the C Standard:

(C99, 6.10.1p4) "After all replacements due to macro expansion and the defined unary operator have been performed, all remaining identifiers (including those lexically identical to keywords) are replaced with the pp-number 0""

Problem

I had envisaged one of these in the project preferences - `TESTING` = `HOST` - `TESTING` = `TARGET` - `TESTING` not defined at all My problem is with the latter. It seems that instead of ``` #if TESTING==HOST #error "HOST defined" // add temporarilly for testing porpoises #endif ``` I need to code ``` #ifdef TESTING #if TESTING==HOST #error "HOST defined" // add temporarilly for testing porpoises #endif #endif ``` I am convinced that this is not-standard behaviour, since if `TESTING` is not defined then it certainly doesn't equal `HOST`, and I do not need that extra `#ifdef TESTING` with the GCC compiler. However, when I use the Atmel AVR Studio (which I think is based on MS Visual Studio), it is necessary to add that initial `#ifdef TESTING` in a few dozen places :-( It looks like I have no choice, but I just wondered if any C standard acually requires this.

Original source