Roberto Waltman <> writes:
> Eliot <> wrote:
>>I have a project which may be compiled with some #defines.
>>
>>Say:-
>>#define firstdef
>>#define seconddef
>>
>>If no defines are present or only one is present all is OK. I would
>>like to add a self check to the code that prevents compilation if both
>>#defines are present. Is this possible?
>
> #if defined(fistdef) && defined(secondef)
> #error Don't do this!
> #endif
The text following "#error" must be a sequence of preprocessing
tokens. The unmatched apostrophe violates this requirement. C99
6.4p3 says:
The categories of preprocessing tokens are: header names,
identifiers, preprocessing numbers, character constants, string
literals, punctuators, and single non-white-space characters
that do not lexically match the other preprocessing token
categories. If a ' or a " character matches the last category,
the behavior is undefined.
It's likely that the compiler will either complain about the
apostrophe, or just incorporate it into the error message, but it's
not guaranteed; conceivably the entire #error directive could be
quietly ignored, or something *really* bad could happen.
It's better to use a valid string literal:
#error "Don't do this!"
Amusingly, Richard Tobin suggested something very similar:
#error Mustn't define both
--
Keith Thompson (The_Other_Keith)
kst- <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"