Solved

[noob][c++]  comments

Posted on 2007-11-17
5
199 Views
Last Modified: 2010-04-01
how many ways are there in comment in the c++ language?


I know   //


are there any others?
0
Comment
Question by:Troudeloup
5 Comments
 
LVL 7

Accepted Solution

by:
UrosVidojevic earned 100 total points
ID: 20303862
- The /* (slash, asterisk) characters, followed by any sequence of characters (including new lines), followed by the */ characters. This syntax is the same as ANSI C.

- The // (two slashes) characters, followed by any sequence of characters. A new line not immediately preceded by a backslash terminates this form of comment. Therefore, it is commonly called a "single-line comment."

http://msdn2.microsoft.com/ja-jp/library/k1dbk8bw(VS.80).aspx
http://cplus.about.com/od/learning1/ss/clessonone_8.htm


0
 
LVL 40

Assisted Solution

by:evilrix
evilrix earned 100 total points
ID: 20303886
See below...
// This is C++ style commenting and is preferred
 

/*

** This is C style commenting but it not often used in C++

** as it can cause problems with nested comments

** /* like this which will not compile */  so prefer to use C++

** style unless your code really is C only

*/

Open in new window

0
 
LVL 53

Assisted Solution

by:Infinity08
Infinity08 earned 200 total points
ID: 20303910
Wow, I'm impressed by the syntax checks in the code snippets !!

Technically, the following is not called "commenting", but it does make part of the code invisible to the compiler :

    some_code_here();

#if 0

    this_code_is_hidden();

#endif

    and_we_resume_here();

Open in new window

0
 
LVL 53

Assisted Solution

by:Infinity08
Infinity08 earned 200 total points
ID: 20303913
Note that the #if 0 technique is an easy way to hide blocks of code without suffering from the nested comments problem evilrix mentioned. You just change #if 0 to #if 1 if you want to enable the block again :)
0
 
LVL 11

Assisted Solution

by:DeepuAbrahamK
DeepuAbrahamK earned 100 total points
ID: 20303951
There are only 2 ways of commenting in c++ as mentioned above. However the preprocessor tells the compiler to ignore or include certain blocks which is more or less similar to commenting when you look at compiler point of view

 #if MY_DEBUG
//some code
#endif

This will get compiled only if you define MY_DEBUG in preporcessor or like
 #define MY_DEBUG

Best Regards,
DeepuAbrahamK
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now