473,804 Members | 3,126 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Comments format: comments extending over multi-line

Hi,

Have a query regarding comments that extend over multiple-lines. Would
like to know if the standard's view of this, so that we can create a
code which doesn't run into compiler specific issues.

1. A normal comments is
/* comment text */

2. A multiple line comment is
/* comment text <new line>
more comment text <new line>
.... <many new lines>
comment text */

1 is fairly common. Does the standard say anything about format 2 ? I
suspect different compilers might interpret 2 differently so the
question.

Any opinions or views on this issue are also welcome.

Sachin

Nov 14 '05 #1
10 2100
"Monk" <sc******@gmail .com> wrote:
1. A normal comments is
/* comment text */

2. A multiple line comment is
/* comment text <new line>
more comment text <new line>
... <many new lines>
comment text */

1 is fairly common. Does the standard say anything about format 2 ?


Yes. It is legal.

From n869.txt, 6.4.9:
# [#1] Except within a character constant, a string literal,
# or a comment, the characters /* introduce a comment. The
# contents of a comment are examined only to identify
# multibyte characters and to find the characters */ that
# terminate it.

Note: _only_ for mb characters and */. Anything else, including
newlines, is ignored.

Richard
Nov 14 '05 #2
Monk wrote:
Hi,

Have a query regarding comments that extend over multiple-lines. Would
like to know if the standard's view of this, so that we can create a
code which doesn't run into compiler specific issues.

1. A normal comments is
/* comment text */

2. A multiple line comment is
/* comment text <new line>
more comment text <new line>
.... <many new lines>
comment text */

1 is fairly common. Does the standard say anything about format 2 ? I
Are you joking? format 2 is widely used.

Krishanu
suspect different compilers might interpret 2 differently so the
question.

Any opinions or views on this issue are also welcome.

Sachin

Nov 14 '05 #3
Monk wrote:
Hi,

Have a query regarding comments that extend over multiple-lines. Would
like to know if the standard's view of this, so that we can create a
code which doesn't run into compiler specific issues.

1. A normal comments is
/* comment text */

2. A multiple line comment is
/* comment text <new line>
more comment text <new line>
... <many new lines>
comment text */

1 is fairly common. Does the standard say anything about format 2 ? I
suspect different compilers might interpret 2 differently so the
question.

Any opinions or views on this issue are also welcome.


Your C text book should tell you that format 2 is completely standard.
You can have as many new lines as you want arranged however you want
between the /* and */
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Nov 14 '05 #4
"Monk" <sc******@gmail .com> writes:
Have a query regarding comments that extend over multiple-lines. Would
like to know if the standard's view of this, so that we can create a
code which doesn't run into compiler specific issues.

1. A normal comments is
/* comment text */

2. A multiple line comment is
/* comment text <new line>
more comment text <new line>
... <many new lines>
comment text */


Both forms are perfectly legal; any compiler that breaks on either of
them is badly broken and should not be trusted.

To stray a bit from the question, if I write a multi-line comment
block I generally try to mark each line:

/*
* Comment line 1
* Comment line 2
* Comment line 3
*/

but that's just a matter of visual style. The extra '*' characters
are simply part of the comment.

Note also that comments don't nest; a "/*" within a comment has no
special meaning:

/* This is /* just a single comment */
/* This is /* not */ a nested comment */

On the second line, the comment ends with the first "*/", and what
follows is probably a syntax error.

Again, any compiler that gets this wrong should not be trusted.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #5
On Wed, 20 Apr 2005 08:50:09 GMT, Keith Thompson
<ks***@mib.or g> wrote:
To stray a bit from the question, if I write a multi-line comment
block I generally try to mark each line:

/*
* Comment line 1
* Comment line 2
* Comment line 3
*/

but that's just a matter of visual style. The extra '*' characters
are simply part of the comment.
My preferred editor (vim) puts those in automatically in C mode (by
default, it can be turned off if the "house style" is different but
that's the way I prefer it).
Note also that comments don't nest; a "/*" within a comment has no
special meaning:

/* This is /* just a single comment */
/* This is /* not */ a nested comment */

On the second line, the comment ends with the first "*/", and what
follows is probably a syntax error.


Some compilers warn about putting /* inside a comment, because a lot of
the time when people do that they are used to (or porting code from)
non-standard compilers which allow nested comments (as I recall some
compilers have an option to allow nested comments for compatibility
with old code).

Chris C
Nov 14 '05 #6
Monk wrote:
Hi,

Have a query regarding comments that extend over multiple-lines. Would
like to know if the standard's view of this, so that we can create a
code which doesn't run into compiler specific issues.

1. A normal comments is
/* comment text */

2. A multiple line comment is
/* comment text <new line>
more comment text <new line>
.... <many new lines>
comment text */

1 is fairly common. Does the standard say anything about format 2 ? I
suspect different compilers might interpret 2 differently so the
question.

Any opinions or views on this issue are also welcome.

Sachin

Both 1. and 2. are allowed.

What you will find differences on are nested comments, e.g.

1 /* Comment 1
2 /* Nested comment */
3 */

Some compilers will see a nested comment and see that line 3 contains
the end of the comment, other compilers will see line 2 ending the
comment and fail compilation on line 3.

I don't know if nested comments are part of the standard.
Nov 14 '05 #7
Jason Curl <j_********@mot orola.com> writes:
[...]
What you will find differences on are nested comments, e.g.

1 /* Comment 1
2 /* Nested comment */
3 */

Some compilers will see a nested comment and see that line 3 contains
the end of the comment, other compilers will see line 2 ending the
comment and fail compilation on line 3.

I don't know if nested comments are part of the standard.


No, nested comments are not part of the standard. Since some code
actually depends on a "/*" within a comment being ignored, a compiler
that allowed nested comments (at least in its default mode) would
cause problems.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #8
Thanks a lot for the replies. They have been most helpful.

Cheers,
Sachin

Nov 14 '05 #9
Chris Croughton wrote:

On Wed, 20 Apr 2005 08:50:09 GMT, Keith Thompson

[...]
Note also that comments don't nest; a "/*" within a comment has no
special meaning:

/* This is /* just a single comment */
/* This is /* not */ a nested comment */

On the second line, the comment ends with the first "*/", and what
follows is probably a syntax error.


Some compilers warn about putting /* inside a comment, because a lot of
the time when people do that they are used to (or porting code from)
non-standard compilers which allow nested comments (as I recall some
compilers have an option to allow nested comments for compatibility
with old code).


I think that's mostly from people commenting out blocks of lines with /* */
and ending up with:

/* comment this out

some old code;
some more old code; /* a comment */
even more old code;

end of comment */
On the other hand, I vaguely remember a long time ago a compiler which was
broken enough to treat "/*" within a string literal as a begin-comment.
This, of course, did nasty things with constructs like:

sprintf(namebuf ,"%s/*.*",path);

On the other other hand, my memory isn't what it used to be. ;-)

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer .h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:Th***** ********@gmail. com>

Nov 14 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
2062
by: Ian Hickson | last post by:
A group of us have been unofficially working on a proposal of extensions to HTML4's Forms chapter, and would like to get input from a wider range of people now that we think our draft proposal is reaching a stable stage: http://www.whatwg.org/specs/web-forms/2004-06-27-call-for-comments/ Some of the features we are proposing include new input control types for dates, times, e-mail addresses, and numbers; a new client-side validation...
1
1740
by: Jonnie | last post by:
I am in the process of building an employee database for use by the management team here. They current have Access 97 (I am working on getting them to upgrade to at least 2000). For the most part I have it under control. There are several points that have popped up as wanted features and I need to verify somethings. 1. We now want to add the ability to add comments/notes with time and date stamps to an employees record. These comments...
0
2343
by: Klaus Bonadt | last post by:
I would like to parse an email, which I receive from a pop3 account. While the subject and the sender's email address are probably easy to determine, the body seems to be more difficult because of multi-part messages in MIME format. I am interested only in the plain text. Do you know an easy way to retrieve plain text of the body from an email message? Maybe a class, which can be constructed using the whole message string as a parameter...
2
1201
by: Vivek Kumar | last post by:
Hi all, I have to write a network server (sort of) and I am looking for your valuable comments. Currently I have written a prototype in VB6 but it can only handle up to 30 or so clients. I need to upgrade the application so that it can handle up to 1000-1500 clients at a time (later if every thing works fine then hoping for 5000-6000 client). The scenario is as follows.
5
3836
by: vbgunz | last post by:
Hello everyone. I own two books. Learning Python and Python in a nutshell. When cross referencing the two books to try and clarify the ideas behind extending methods and delegates, this is where confusion veered it's ugly head :( Learning Python explains on page 324: Class Interface Techniques (21.3.3 in the ebook) the following is an extender method. ''' #################################### '''
11
10579
by: shsandeep | last post by:
I used the following query to retrieve the date in dd-mon-yyyy format. db2 => SELECT RTRIM(CHAR(DAY(COVG_TYP_STRT_DT))) || '-' || RTRIM(MONTHNAME(COVG_TYP_STRT_DT)) || '-' || RTRIM(CHAR(YEAR(COVG_TYP_STRT_DT))) FROM twd_coverage_type 1 ---------------------------------------------------------------------------------------------------------------------------- 6-May-2006 1 record(s) selected.
0
2325
by: MAILER-DAEMON | last post by:
This is a multi-part message in MIME format. --FLMNOQRSTUVXYZabcefghjklmnoqrstuvxyz0124 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit This message has been processed by Symantec AntiVirus. instruction.exe was infected with the malicious virus W32.Mydoom!gen and has been deleted because the file cannot be cleaned. --FLMNOQRSTUVXYZabcefghjklmnoqrstuvxyz0124
0
1568
by: vishnu | last post by:
Hello All, I have embedded python 2.5 in to my C application. As we need the python scripts to run in multi threaded environment I have used Py_NewInterpreter() and Py_EndInterpreter each time I execute a run script function. The code is as follows: RunScript(char *pScriptName,char *pFuncName,...) { PyEval_AcquireLock()
3
3679
by: katis | last post by:
Hi all :) Is it posible in xsd to change only minOccurs value of element in complex type by extending this type? The problem I'm trying to solve is this: I have two complex types - "TextField" and "FileChooser". Here is definition of "TextField" <xsd:complexType name="TextField">
1
1714
by: =?iso-8859-1?q?Fran=E7ois_Beretti?= | last post by:
Hi, I want to design an XML format for my application. Documents using this format will describe LDAP classes and attributes. I have found the DSML format ( http://xml.coverpages.org/dsmlv1.html ) which does a part of what I want. But I want to add some information to it. For example, with DSML I can write :
0
9704
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9572
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10562
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10319
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10303
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6845
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5639
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4282
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2978
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.