How to force cpp to abort?

Karl Heuer karl at haddock.ima.isc.com
Mon Aug 13 12:51:27 AEST 1990


In article <MIKEG.90Aug11180036 at c3.c3.lanl.gov> mikeg at c3.c3.lanl.gov (Michael P. Gerlek) writes:
>[If none of the preprocessor conditions hold, I want to abort.  How?]

Use `#error put_some_text_here'.  This is the ANSI C solution.

I presume you also want this to work on pre-ANSI compilers (since you used
`#else\n#if' instead of the cleaner `#elif' construct).  If you add a leading
space, i.e. ` #error', it should be invisible to pre-ANSI compilers that would
complain about unknown cpp-control lines.  (ANSI allows horizontal whitespace
before `#' as well as after.)  Then an attempt to compile in a pre-ANSI
environment where none of the conditionals holds should get an `illegal
character' warning when the `#' is encountered in the next compiler pass.

If you insist on aborting during the preprocessor pass, you could use
`#include "/-/put_some_text_here/-/", which is what I used to use before
`#error' was invented.

Karl W. Z. Heuer (karl at kelp.ima.isc.com or ima!kelp!karl), The Walking Lint



More information about the Comp.lang.c mailing list