quotes inside #if 0

Karl Heuer karl at haddock.ima.isc.com
Tue Sep 5 05:43:10 AEST 1989


In article <2014 at munnari.oz.au> ok at cs.mu.oz.au (Richard O'Keefe) writes:
>	#if 0 ... [English text and C examples] ... #endif
>The compiler sees words like "don't" in the English text and snarls that
>these are unterminated character constants.  This used to be perfectly
>good C...

No, what you really mean is that you used to use a compiler that happened not
to complain about that, and now you use one that does.  The introduction of
ANSI C between the two events is largely coincidental.  It never was good C.

Generally, if you want to hide English text from the compiler, you should use
/*...*/, whereas if you want to hide C code, you should use #if...#endif.  I
infer from your posting that this particular instance is English text that
happens to include C code within the running text, i.e. this C code is meant
to be read by humans rather than being a piece of former code that's been
inactivated.  Probably your best bet is to move the comments into the English
text, omitting the comment delimiters.

>Is there a way of having mixed English text and C fragments (possibly
>including C comment delimiters) in a C program which _will_ work in ANSI C?

Alas, there is no perfect commenting convention; unless it's all done with an
awkward prefix like a Hollerith constant, there's always  something that
cannot appear literally in a comment.  In C it's the string "*/", and I'm
afraid you'll have to live with it, or find a new language.  (C++ comes to
mind.  It has remainder-of-line comments, which are okay if you don't mind
putting the prefix on each line.)

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



More information about the Comp.lang.c mailing list