By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,260 Members | 1,305 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,260 IT Pros & Developers. It's quick & easy.

what's the difference between the two kinds comment syntaxs?

P: n/a
we can use
1) // my comments a
2) /* my comments b */
when we want to add some comments.

I know some compilers just support the 2nd syntax, but normally both of
these 2 syntaxs are supported by most of the compilers. But what are
the difference for those two syntaxs in the sense for the compiler, if
it support both. Is one of them will be processed faster?

Another question, if I write comments in NON-Alfa-Beta languages, like
Chinese, will it cause the compiler to use more time?

thanks

Jul 7 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
cdrsir <cd****@gmail.comwrote:
we can use
1) // my comments a
This type of comment will automatically end by the end of the line.
2) /* my comments b */
This one will end only when */ is found. This implies that you can
comment multiple lines using just /* and */ instead of having to start
each line with //.

hth
--
jb

(reply address in rot13, unscramble first)
Jul 7 '06 #2

P: n/a
cdrsir wrote:
we can use
1) // my comments a
2) /* my comments b */
when we want to add some comments.

I know some compilers just support the 2nd syntax,
Well, if you find one that doesn't support the first syntax, throw that
compiler away.
but normally both of these 2 syntaxs are supported by most of the
compilers. But what are the difference for those two syntaxs in the sense
for the compiler, if it support both. Is one of them will be processed
faster?
No. One is for single-line comments, the other for multi-line comments.
That's all there is about it.
Another question, if I write comments in NON-Alfa-Beta languages, like
Chinese, will it cause the compiler to use more time?
Why are you concerned about compile time? The lexical analyzer is probably
the part that takes the smallest percentage of the total execution time of
the compiler. And for throwing away characters, it doesn't really matter
much what those characters are.
If you really want to speed up compilation, use precompiled headers if the
compiler supports it. Another way is to switch off optimizations, since the
optimizer is probably the part taking the majority of the compile time.
However, your program will of course be less optimal.

Jul 7 '06 #3

P: n/a
"cdrsir" <cd****@gmail.comwrote in message
news:11**********************@p79g2000cwp.googlegr oups.com...
we can use
1) // my comments a
2) /* my comments b */
when we want to add some comments.

I know some compilers just support the 2nd syntax, but normally both of
these 2 syntaxs are supported by most of the compilers. But what are
the difference for those two syntaxs in the sense for the compiler, if
it support both. Is one of them will be processed faster?

Another question, if I write comments in NON-Alfa-Beta languages, like
Chinese, will it cause the compiler to use more time?

thanks
// is for single line coments and comments everything til the end of hte
line.

/* */ is for multi line comments and /* comments eveyrthing until it finds
another */ no matter how far away that is.

I alwasy use // comments to comment code.

When I temporarily comment out a block of code (for testing or such) I use
/* */ one reason so I can find it again easier. If I searched for // I
would find way too many lines, but since I don't use /* */ for "normal"
comments, it will only exist where I used to to comment out a block of code.
Jul 7 '06 #4

P: n/a

Jakob Bieling wrote:
cdrsir <cd****@gmail.comwrote:
we can use
1) // my comments a

This type of comment will automatically end by the end of the line.
2) /* my comments b */

This one will end only when */ is found. This implies that you can
comment multiple lines using just /* and */ instead of having to start
each line with //.
You can also use /* */ to comment out part of a line should you wish
to.

void foo(int param1, int param2, /* int param3 */);

/* */ comments aren't clever enough to nest so you can get caught out
sometimes if you try to use them to temporarily remove a chunk of code,
for example during debugging, if that chunk of code already contains /*
*/ comments. For example, I might have this function somewhere in my
code.

void foo()
{
// code here

/*
Here is a multi-line comment
to help the reader understand what is going on
*/

// more code here
}

Now suppose I'm debugging. I want to simplify the code to track down
the problem. One of the things I need to do is temporarily comment out
the entire body of foo so it can be eliminated from my investigation.
The easiest way to do that is to add /* immediately after the opening
brace at the start of the function and add */ immediately before the
closing brace at the end of the function. Except with m multi-line
comment in there that won't work. The /* */ comment will end at the end
of the multi-line comment. The later part of the foo function (where I
wrote "more code here") will still be there not commented out. And the
*/ immediately before the closing brace of foo will be a simple syntax
error.

For this reason I personally never use /* */ for comments that I intend
to keep.

Gavin Deane

Jul 7 '06 #5

P: n/a

cdrsir wrote:
we can use
1) // my comments a
2) /* my comments b */
when we want to add some comments.
There is a third way - you can also use #if 0 if you need to comment
out a block of code, thus:

#if 0
void dont_want_this_any_more()
{ ... }
#endif

This is useful if you want to avoid /* .. */ nesting problems.

Jul 7 '06 #6

P: n/a

"cdrsir" <cd****@gmail.comskrev i meddelandet
news:11**********************@p79g2000cwp.googlegr oups.com...
we can use
1) // my comments a
2) /* my comments b */
when we want to add some comments.

I know some compilers just support the 2nd syntax,
That's old C compilers.
but normally both of
these 2 syntaxs are supported by most of the compilers. But what are
the difference for those two syntaxs in the sense for the compiler,
if
it support both. Is one of them will be processed faster?
The difference is that version 2 is from the original C language.
Style 1 was added to C++, and later to C as well.
>
Another question, if I write comments in NON-Alfa-Beta languages,
like
Chinese, will it cause the compiler to use more time?
It might confuse some compilers, not to mention non-chinese
programmers. :-)


Bo Persson
Jul 7 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.