473,406 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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

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
6 2401
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
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
"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

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

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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
137
by: Philippe C. Martin | last post by:
I apologize in advance for launching this post but I might get enlightment somehow (PS: I am _very_ agnostic ;-). - 1) I do not consider my intelligence/education above average - 2) I am very...
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
51
by: jacob navia | last post by:
I would like to add at the beginning of the C tutorial I am writing a short blurb about what "types" are. I came up with the following text. Please can you comment? Did I miss something? Is...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
9
by: DavidB | last post by:
Hi all I have a script that works perfectly in IE but not in FF. I am sure that the problem is easy to resolve, but I seem to be too dumb to figure it out. <html> <head> <script...
5
by: Antonio Parolini | last post by:
What is the difference between: main(......) { exit(0); } and main(......) {
5
by: narutocanada | last post by:
hi what is the difference between the two kinds of brackets? I tried a few examples but I can't make out any real difference: lst = print lst print lst print lst lst = (10, 20, 30) print...
53
by: Gianni Mariani | last post by:
Do you have a preference on maximum line width for C++ code? I've seen the craziest debates on this most silly of topic. I have witnessed engineers spent oodles of time fiddling with line...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.