Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > what's the difference between the two kinds comment syntaxs?

Reply
Thread Tools

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

 
 
cdrsir
Guest
Posts: n/a
 
      07-07-2006
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

 
Reply With Quote
 
 
 
 
Jakob Bieling
Guest
Posts: n/a
 
      07-07-2006
cdrsir <(E-Mail Removed)> wrote:
> 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)


 
Reply With Quote
 
 
 
 
Rolf Magnus
Guest
Posts: n/a
 
      07-07-2006
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.

 
Reply With Quote
 
Jim Langston
Guest
Posts: n/a
 
      07-07-2006
"cdrsir" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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.


 
Reply With Quote
 
Gavin Deane
Guest
Posts: n/a
 
      07-07-2006

Jakob Bieling wrote:
> cdrsir <(E-Mail Removed)> wrote:
> > 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

 
Reply With Quote
 
tragomaskhalos
Guest
Posts: n/a
 
      07-07-2006

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.

 
Reply With Quote
 
Bo Persson
Guest
Posts: n/a
 
      07-07-2006

"cdrsir" <(E-Mail Removed)> skrev i meddelandet
news:(E-Mail Removed) 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Can someone tell me what kinds of questions should be asked inthis list and what kinds in the tutor section? Oscar Benjamin Python 8 02-19-2013 12:12 AM
Re: Can someone tell me what kinds of questions should be asked inthis list and what kinds in the tutor section? Tim Golden Python 2 02-17-2013 09:31 PM
Can someone tell me what kinds of questions should be asked in thislist and what kinds in the tutor section? Claira Python 0 02-17-2013 12:19 AM
what is the difference between the two kinds of brackets? narutocanada@gmail.com Python 10 10-22-2007 02:58 AM
Back and Forth between Two Kinds of Error Messages kvnsmnsn@hotmail.com Java 3 08-03-2006 03:59 AM



Advertisments