// vs /*

R

Robert Gamble

Joe said:
Hi,

Is using // for a comment standard C?

It was standardized in C99 although it was widely supported as a common
extension before that time. It is probably the most widely supported
C99 feature.

Robert Gamble
 
J

Joe Van Dyk

Robert said:
It was standardized in C99 although it was widely supported as a common
extension before that time. It is probably the most widely supported
C99 feature.

That's what I thought.

(I'm converting all our comments to be doxygen-compatible and I prefer
to use ///.)

Thanks,
Joe
 
C

CBFalconer

Robert said:
It was standardized in C99 although it was widely supported as a
common extension before that time. It is probably the most widely
supported C99 feature.

It is also highly unwise to use it in any media (such as usenet)
where line wrapping can occur.
 
C

CBFalconer

Joe said:
That's what I thought.

(I'm converting all our comments to be doxygen-compatible and I
prefer to use ///.)

Not considered wise from a portability viewpoint.
 
T

Tim Prince

CBFalconer said:
Not considered wise from a portability viewpoint.
gcc continues to support both a pre-processor which does not process //
comments, and one which does.
 
Z

Zara

It is also highly unwise to use it in any media (such as usenet)
where line wrapping can occur.

Iif you stuff a really long comment in a single line, you may be
flagged for having very poor coding/commenting style, but it is no
good reason to abandon the use of //

Zara
 
B

Bill Pursell

Zara said:
Iif you stuff a really long comment in a single line, you may be
flagged for having very poor coding/commenting style, but it is no
good reason to abandon the use of //

Is there any good reason to adopt its use? Code should not
depend on white-space between tokens. IMO, using '\n' as the
comment termination character is one of the top 10 really bad
ideas in the history of computing.
 
K

Keith Thompson

Bill Pursell said:
Is there any good reason to adopt its use? Code should not
depend on white-space between tokens. IMO, using '\n' as the
comment termination character is one of the top 10 really bad
ideas in the history of computing.

printf("Hello,
world\n");

Personally, I really like end-of-line comments ("//" in C99 and C++,
"#" in Perl and shell scripting, "--" in Ada). It's easy to comment
out large blocks of code given a decent editor, there's no ambiguity
about nested comments, and if you're looking at the middle of a large
comment block there's no question that it's in a comment block.

But of course it's a matter of taste, and I don't expect to convince
anyone.

One good reason to avoid // comments, as much as I like them, is that
they're not universally supported; another is the Usenet line-wrapping
problem. But the latter could be easily addressed by keeping your
lines reasonably short so they don't wrap.
 
R

Richard Heathfield

Joe Van Dyk said:
Hi,

Is using // for a comment standard C?

Yes and no. Several reasons have been given for avoiding them in your C90
programs, but nobody appears to have mentioned the fact that modding down
ANSI conformance to allow them will, in some implementations, also
necessarily involve removing some other diagnostic messages. For example,
on the implementation I use most during development, enabling // comments
involves disabling a great many ANSI conformance checks. It's too high a
price.
 
K

Kenny McCormack

gcc continues to support both a pre-processor which does not process //
comments, and one which doe

so what? All the world is not GCC.[/QUOTE]

I assume that if I pointed out that Nabisco makes at least 2 kinds of
Oreos, you'd "smartly" point out that "All the world is not Nabisco".
 
R

Richard Bos

so what? All the world is not GCC.

I assume that if I pointed out that Nabisco makes at least 2 kinds of
Oreos, you'd "smartly" point out that "All the world is not Nabisco".[/QUOTE]

If you used it as an argument that Oreos are available everywhere, yes,
that would be a valid counterpoint.

Richard
 
J

Joe Van Dyk

Richard said:
Joe Van Dyk said:




Yes and no. Several reasons have been given for avoiding them in your C90
programs, but nobody appears to have mentioned the fact that modding down
ANSI conformance to allow them will, in some implementations, also
necessarily involve removing some other diagnostic messages. For example,
on the implementation I use most during development, enabling // comments
involves disabling a great many ANSI conformance checks. It's too high a
price.

Hm. What implementations might it hinder ANSI conformance checking?

Thanks,
Joe
 
C

Christopher Benson-Manica

Joe Van Dyk said:
Hm. What implementations might it hinder ANSI conformance checking?

I'm fairly sure Richard uses gcc; passing -ansi to the compiler both
disables support for // comments and enables all sorts of other
conformance checks that, as Richard pointed out, are more or less
indispensable.
 
K

Kenny McCormack

If you used it as an argument that Oreos are available everywhere, yes,
that would be a valid counterpoint.

And who but a paranoid freak would try to draw such a ridiculous
inference?
 
T

Tom St Denis

Joe said:
Hi,

Is using // for a comment standard C?

Use /* */ comments.

Many CC's still don't support //. Mostly because they're C90
compilers.

So instead of going through your code and converting all /* */ to // or
/// just use

/** Doxy comment */

And save yourself a big f'ing headache.

Tom
 
R

Ryan Reich

Personally, I really like end-of-line comments ("//" in C99 and C++,
"#" in Perl and shell scripting, "--" in Ada). It's easy to comment
out large blocks of code given a decent editor, there's no ambiguity
about nested comments, and if you're looking at the middle of a large
comment block there's no question that it's in a comment block.

Nested comments are never ambiguous; only if you are really looking for
complication do they become ambiguous, and in that case, they're just as
ambiguous for // as for /* */. Consider:

/* A comment /* with a comment inside */
// A comment // with a comment inside

Syntactically, they're identical. The most obvious way of parsing comments
will not notice the nesting. How is it more ambiguous for the first whether
or not there's a syntax error? It's possible, even likely, that a human might
find the latter to be clearer, but who cares what humans think about how C
code is parsed? Only the compiler really cares, and the compiler is not
fooled by visual cues like which opening delimiter is closer to the closing
one, when the standard is that "the closing one" matches the _first_ opening
one, not the nearest.

Your first objection, about commenting out large blocks, is not really valid
since to do so with /* requires only two insertions, and you can even make
those on their own new lines, which requires no interference with the existing
text at all. It's actually easier to comment out large blocks this way than
with //.

To uncomment is another story, since text is line-based but /* */ is
non-local, but in practice you have either syntax highlighting, so the editor
knows this non-local information, or you follow a common style and put a * at
the beginning of each commented line, in which case for the purposes of
automation there is no difference between /* */ and //. Apropos of your third
comment, the only difference here between these two is now that for the
former, this is a convention, and for the latter, this is a standard.
Nonetheless, if you are using an editor to create large comments it will
enforce its own conventions consistently.
But of course it's a matter of taste, and I don't expect to convince
anyone.

Of course not. For example, you wisely chose not to name the "decent editor"
with which one would be commenting out code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top