Article View: comp.std.c
Article #2293C needs reliable comments
From: Rahul Dhesi
Date: Mon, 14 Jan 1991 19:54
Date: Mon, 14 Jan 1991 19:54
44 lines
2258 bytes
2258 bytes
The discussion of // comments started me thinking. Did you realize
that C is one of the few programming languages, perhaps the only one,
in which you can never be sure of correctly commenting stuff out?
(a) You can use /* and */ to comment out a block of code. Then
anywhere in that block, if a */ occurs, the comment terminates
prematurely.
(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.
(c) You can use a non-C compiler and use // comments. But if the
compiler isn't pure non-C, your comments may become invalid if a line
ends with a blackslash. And you still can't use // to comment out a
block of code without editing each line.
C badly needs a way of commenting out a block easily. It needs
something like this:
#comment /* begins in column 1; everything following is a comment */
... stuff to be commented out ...
... nac esu #tnemmoc ot peek logla sersu yppah ...
#endc /* first occurrence of #endc in column one ends #comment block */
The #comment...#endc blocks do not nest, and are required to be in
column 1, thus avoiding all necessity for parsing tokens. What's nice
about this scheme is that, in a pinch, you could always used sed or an
equivalent editor to strip out comments if your compiler didn't support
them:
#! /bin/sh
# strip out #comment comments
TMP=/tmp/$$
for file
do
sed -e '/^#comment/,/^#endc/d' < "$file" > $TMP && mv $TMP "$file"
done
So nobody will ever be completely helpless due to lack of downward
compatibility.
--
History never | Rahul Dhesi <dhesi%cirrusl@oliveb.ATC.olivetti.com>
becomes obsolete. | UUCP: oliveb!cirrusl!dhesi
Technical Details
Message-ID:
<2893@cirrusl.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!apple!sun-barr!olivea!tymix!cirrusl!sunstorm!dhesiShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!thunder.mcrcim.mcgill.edu!snorkelwacker.mit.edu!apple!sun-barr!olivea!tymix!cirrusl!sunstorm!dhesi From: dhesi%cirrusl@oliveb.ATC.olivetti.com (Rahul Dhesi) Newsgroups: comp.std.c Subject: C needs reliable comments Message-ID: <2893@cirrusl.UUCP> Date: 14 Jan 91 19:54:24 GMT Sender: news@cirrusl.UUCP Organization: Cirrus Logic Inc. Lines: 44