comment style

Stephen Clamage steve at taumet.com
Sun Jan 13 05:19:36 AEST 1991


thorinn at diku.dk (Lars Henrik Mathiesen) writes:

>brnstnd at kramden.acf.nyu.edu (Dan Bernstein) writes:
><Then you have a push-pull in the preprocessor between the #define, which
><takes everything up to the next newline, and the //, which takes
><everything up through the next newline. I'd say the #define should win...

>If the #define wins, // comments cannot be used as line continuations
>in macros. Pity, because I liked your idea of merging the comment and
>continuation mechanisms.

// comments extend *to* the end of the line, not through it.  They cannot
be used as line continuations.  So

	#define foo bar		// use bar instead of foo
	blah blah

is equivalent to

	#define foo bar
	blah blah

You also cannot use line continuation in the presence of // comments, because
the ANSI "phases of translation" apply.  The line continuation is applied
before comments are recognized, and everything past the // is lost.

	#define foo	// comment here	\ 
		bar

first becomes
	#define foo	// comment here bar
and then becomes
	#define foo
which presumably is not what was intended.

NOTE:  Not all existing preprocessors treat // comments the same way.
What I have stated above is as specified in the latest documentation
for C++.  Some existing (older) C++ compilers behave differently.
For C, // comments are an extension, not part of any standard, so who
knows what different compilers will do?
-- 

Steve Clamage, TauMetric Corp, steve at taumet.com



More information about the Comp.std.c mailing list