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

C

cdrsir

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
 
J

Jakob Bieling

cdrsir said:
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
 
R

Rolf Magnus

cdrsir said:
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.
 
J

Jim Langston

cdrsir said:
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.
 
G

Gavin Deane

Jakob said:
This type of comment will automatically end by the end of the line.


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
 
T

tragomaskhalos

cdrsir said:
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.
 
B

Bo Persson

cdrsir said:
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
 

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,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top