According to the C language standard, the lines between #if 0
and #endif
are required only to contain preprocessing tokens, so most kinds of completely malformed syntax e.g. #foo
or #include [bar]
are allowed (silently ignored); GCC and Microsoft C++ do indeed silently ignore such.
An @
does not as far as I can see correspond to any preprocessing token so should still be a syntax error. GCC and Microsoft C++ silently ignore it. Is this effectively a language extension or am I missing something?
Does anyone actually use the ability to put malformed syntax between #if 0
and #endif
in practice?
Both the C and C++ standard contain a special 'escape clause' in their grammar that makes that every non-white-space character is (part of) a preprocessing token. For this reason, whatever you put in a block between #if 0
and #endif
can almost never cause a compilation error. The only exception are mismatched quotes for character and string literals.
And yes, I regularly put malformed syntax between #if 0
and #endif
to disable some partially-written code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With