comment style

Richard Minner rtm at christmas.UUCP
Wed Jan 9 17:12:26 AEST 1991


In article <17444:Jan804:03:3291 at kramden.acf.nyu.edu> brnstnd at kramden.acf.nyu.edu (Dan Bernstein) writes:
>But that's the beauty of end-of-line comments: You *automatically*
>delete everything, including the newline itself. // is both the comment
>mechanism and the continuation mechanism. All characters past //,
>through the newline, are ignored.
>
>Apparently Microsoft C doesn't do this right. Oh, well.

No, // doesn't necessarily eat the newline in C++:
ARM 2.2 Comments: ... The characters // start a comment, which terminates
at the end of the line on which they occur.

We'll let the ANSI folks tell us if "line" means "physical line" or
"logical line", but in either case it doesn't seem to imply the
logical joining of the current line with the next.  If it did, then
	#define THIS	// blah blah
	#define THAT	// blah blah
would break.  And so would
	...
	#endif //...
	<code>

Remember, newlines are usually just white space, but not always to
the preprocessor.  I personally don't hate /* */ so much, but just
to keep this wonderous thread going (anyone keeping count?) there's
another really super big advantage of // that I haven't seen mentioned.
If you want to write a header for a function or file and include
an example of usage that actually looks like regular code with
normal comments, you can't do it with /* */ without resorting
to some pretty ugly guck with #if/#endif.  With // it's trivial.

-- 
Richard Minner  || {uunet,sun,well}!island!rtm     (916) 736-1323 ||
                || Island Graphics Corporation     Sacramento, CA ||



More information about the Comp.std.c mailing list