Behavior of #error preprocessor directive

J.T. Conklin jtc at van-bc.wimsey.bc.ca
Tue Jan 8 09:26:23 AEST 1991


Is use of the #error preprocessor directive required (or permitted) to
halt compilation of a source module.  I don't have a copy of the C
standard, and K&R2 says nothing much more than the token sequence
following the directive will be printed.

I ask this because I believe both behaviors (halting or continuing)
are useful.  But it would be even more useful if both mechanisms were
available separately.


For example, I currently use #error to halt compilation whenever
compile-time consistency checks fail; but it would be useful to use
a #warning directive for cases like this:

    #ifdef M_XENIX
    #warning Use work around for bug brain dead SCO/Microsoft C compiler
	.....
    #else
	.....
    #endif

If the text of the #warning was printed during compilation, it would
remind me that I could remove the work around whenever SCO releases a
fixed version of their compiler (Granted, that is extremely unlikely :-).


I've seen a lot of code with little workarounds that still remain
years after the original bug that made the workaround necessary has be
squashed.  Responsibility for maintaining a piece of software may 
change hands many times during its life.  Proper use of such #warnings
might help reduce the burden of software maintenance.

Has anyone experimented with user-introduced warning messages in C? In
any other language?  Do they work, or do programmers neglect to use
them?  Is there a real need for such a feature?


In any case, was anything like my #warning directive discussed during
the standardization process?  If this turns out to be a good idea,
there should be plenty of time to slice it into compilers and get some
feel of weather its really worthwhile.  When does the standard get
reviewed again anyway? '95? '00?

	--jtc


-- 
J.T. Conklin	jtc at wimsey.bc.ca, ...!{uunet,ubc-cs}!van-bc!jtc



More information about the Comp.lang.c mailing list