How to force cpp to abort?

Karl Heuer karl at haddock.ima.isc.com
Thu Aug 16 08:29:09 AEST 1990


In article <MIKEG.90Aug13092741 at c3.c3.lanl.gov> mikeg at c3.c3.lanl.gov (Michael P. Gerlek) writes:
>it's almost what I want (I missed the #error directive when I looked thru
>K&R) -- But it's still ANSI-only...

Huh?  Read again what I wrote.  If you spell it ` #error', with a leading
space, then both Classic and ANSI compilers should die at that point (though
for different reasons).  And the `#include "/-/error_message_here/-/"' hack
also works on both dialects, though I prefer the former method.

>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...

That's what `#error' is for.  Note that there's *no* construct which is
guaranteed to stop compilation; a `friendly' implementation might decide to
delete everything that causes an error (after issuing at least one diagnostic,
of course), and add `main(){}' at the end if necessary, so that a compilation
never fails.  But the vendors know we wouldn't like that, so they don't do it.
The same applies to `#error'.

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