How to force cpp to abort?
Michael P. Gerlek
mikeg at c3.c3.lanl.gov
Tue Aug 14 01:27:41 AEST 1990
In article <17377 at haddock.ima.isc.com>,
karl at haddock.ima.isc.com (Karl Heuer) writes:
> In article <MIKEG.90Aug11180036 at c3.c3.lanl.gov> I (Michael P. Gerlek) wrote:
> > [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).
Yup, bingo.
> 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.
Most of the email responses I got said the same thing, and it's
almost what I want (I missed the #error directive when I looked thru
K&R) -- But it's still ANSI-only...
So, academic question: from what I understand, #error isn't guaranteed
to stop compilation. Can someone tell me why there isn't something
like an "#abort error-message-here" directive that *would* terminate?
Seems like this'd be really useful...
[ M.P.Gerlek (mikeg at lanl.gov) -
[ Los Alamos Nat'l Lab / Merrimack College -
[ Disclaimer: Yes, Mom, I'll play nice. -
[ "My other machine *used* to be an XMP." -
More information about the Comp.lang.c
mailing list