C needs reliable comments

Dave P. Schaumann dave at cs.arizona.edu
Thu Jan 24 11:14:23 AEST 1991


In article <2915 at cirrusl.UUCP> dhesi%cirrusl at oliveb.ATC.olivetti.com (Rahul Dhesi) writes:
|I wrote (among other things):
|
|   (b) You can use #if 0 and #endif to comment out a block of code.
|   Then if you have an invalid token or unbalanced quotes between
|   these, the "commented out" block of code, the compiler may abort
|   compilation.
|
|In <14884 at smoke.brl.mil| gwyn at smoke.brl.mil (Doug Gwyn) responds:
|
||This is fallacious.  If you start with valid code and "comment out" a
||section to leave valid code using #if 0 and #endif, there is no problem.
||If you wish to adopt the thesis that random character strings should be
||accepted as valid C program source code, you're [name-calling deleted].
|
|If you have C code and isn't working right, you may want to temporarily
|comment it out and replace it with a working stub.

No.  Not comment out.  I would use the conditional compilation operators,
though.

|Furthermore, the term "code" includes not only the C part but also any
|other text that is part of a C source file but is not intended for the
|compiler.

Maybe for you.  The way I (and obviously ANSI) see it, is that code is code,
and comments are comments, and never the twain shall meet.  Comments can
be *any* text (except, of course, the comment-end delimiter.  If you want
to include something that is a comment, use /* */.

If you want to include something that is *code* (ie at least well formed
tokens), use the #if/#endif operators.  I think that ANSI is well within
the bounds of reasonableness to require that everything within the
conditional compilation operators be well formed tokens.  After all, it
is supposed to be code -- something that (perhaps, with a little work) someday
will be compiled.

| [example of comment/conditional compilation use deleted]

C is certainly not perfect.  No language is.  Comments cannot include random
text, and it is certainly reasonable that article headers and signatures
might contain "*/".  Personnaly, I strip off the non-code portions in this
case, and save them to a seperate file.

This is my final word on this thread: (I promise :)
	-comments are for hiding non-program text from the compiler.
	-the conditional compilation directives are for hiding code
	 from the compiler.

If you try to use one for the other's job, *you will have problems*.

|Rahul Dhesi <dhesi%cirrusl at oliveb.ATC.olivetti.com|
|UUCP:  oliveb!cirrusl!dhesi


Dave Schaumann		|  And then -- what then?  Then, future...
dave at cs.arizona.edu	|  		-Weather Report



More information about the Comp.std.c mailing list