468,457 Members | 1,598 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,457 developers. It's quick & easy.

nested comments

Hi Everyone,

I was wondering about the nested comments and the reason why it is
not acceptable...

/*
first
/*
second
*/
*/

I guess it is easy for any lexer to recognize such text with the help
of recursive grammar rule and ignore them...
does anyone have any idea about the reason why this is not allowed?
Thanks in advance!!!
Dec 26 '07 #1
10 4988
On Dec 26, 4:06 pm, Rahul <sam_...@yahoo.co.inwrote:
Hi Everyone,

I was wondering about the nested comments and the reason why it is
not acceptable...

/*
first
/*
second
*/
*/

I guess it is easy for any lexer to recognize such text with the help
of recursive grammar rule and ignore them...
does anyone have any idea about the reason why this is not allowed?

Thanks in advance!!!
I think comment is used to write something about the code. If you want
to disable some code temporarily, "#if 0" is better.
Dec 26 '07 #2
On Dec 26, 1:06 pm, Rahul <sam_...@yahoo.co.inwrote:
Hi Everyone,

I was wondering about the nested comments and the reason why it is
not acceptable...

/*
first
/*
second
*/
*/

I guess it is easy for any lexer to recognize such text with the help
of recursive grammar rule and ignore them...
does anyone have any idea about the reason why this is not allowed?

Thanks in advance!!!
Hi,

the implementation of the comments are like that, once the comments is
started
it will search for the counterpart.

You can try nestin like that,
/*
first
\/*
second
*\/
*/

-aims
Dec 26 '07 #3
Rahul wrote:
Hi Everyone,

I was wondering about the nested comments and the reason why it is
not acceptable...
Mostly because the language definition says so, I guess.
>
/*
first
/*
second
*/
*/

I guess it is easy for any lexer to recognize such text with the help
of recursive grammar rule and ignore them...
does anyone have any idea about the reason why this is not allowed?
Maybe because there is no need for it.

Dec 26 '07 #4
On Dec 26, 4:43 pm, Rolf Magnus <ramag...@t-online.dewrote:
Rahul wrote:
Hi Everyone,
I was wondering about the nested comments and the reason why it is
not acceptable...

Mostly because the language definition says so, I guess.
/*
first
/*
second
*/
*/
I guess it is easy for any lexer to recognize such text with the help
of recursive grammar rule and ignore them...
does anyone have any idea about the reason why this is not allowed?

Maybe because there is no need for it.
well, sometimes i does make sense to properly align the comments...
Dec 26 '07 #5
On 2007-12-26 06:57:14 -0500, Rahul <sa*****@yahoo.co.insaid:
On Dec 26, 4:43 pm, Rolf Magnus <ramag...@t-online.dewrote:
>Rahul wrote:
>>Hi Everyone,
>>I was wondering about the nested comments and the reason why it is
not acceptable...

Mostly because the language definition says so, I guess.
>>/*
first
/*
second
*/
*/
>>I guess it is easy for any lexer to recognize such text with the help
of recursive grammar rule and ignore them...
does anyone have any idea about the reason why this is not allowed?

Maybe because there is no need for it.

well, sometimes i does make sense to properly align the comments...
Why would you comment on comments?

--

-kira

Dec 26 '07 #6
On 2007-12-26 02:06:00 -0600, Rahul <sa*****@yahoo.co.insaid:
Hi Everyone,

I was wondering about the nested comments and the reason why it is
not acceptable...
It is prohibited by the standard, Section 2.7.

-dr
Dec 26 '07 #7
On Dec 26, 8:07 pm, Dave Rahardja
<drahardja.place...@sign.here.pobox.comwrote:
On 2007-12-26 02:06:00 -0600, Rahul <sam_...@yahoo.co.insaid:
Hi Everyone,
I was wondering about the nested comments and the reason why it is
not acceptable...

It is prohibited by the standard, Section 2.7.

-dr
I understand that it is not allowed, but its not a big deal for a
compiler to ignore nested comments... (compilers can detect nested
ifs, nested blocks... etc) i was just wondering if there was any
specific reason of not allowing nested comments...
Dec 26 '07 #8
On 2007-12-26 18:02, Rahul wrote:
On Dec 26, 8:07 pm, Dave Rahardja
<drahardja.place...@sign.here.pobox.comwrote:
>On 2007-12-26 02:06:00 -0600, Rahul <sam_...@yahoo.co.insaid:
Hi Everyone,
I was wondering about the nested comments and the reason why it is
not acceptable...

It is prohibited by the standard, Section 2.7.

-dr

I understand that it is not allowed, but its not a big deal for a
compiler to ignore nested comments... (compilers can detect nested
ifs, nested blocks... etc) i was just wondering if there was any
specific reason of not allowing nested comments...
Originally it was probably to make life easier for the compiler developers.

--
Erik Wikström
Dec 26 '07 #9
On Wed, 26 Dec 2007 00:06:00 -0800 (PST), Rahul <sa*****@yahoo.co.in>
wrote in comp.lang.c++:
Hi Everyone,

I was wondering about the nested comments and the reason why it is
not acceptable...

/*
first
/*
second
*/
*/

I guess it is easy for any lexer to recognize such text with the help
of recursive grammar rule and ignore them...
does anyone have any idea about the reason why this is not allowed?
What is the reason that you think it should be allowed?

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
Dec 26 '07 #10
There are other quirks too. For example, assume you have this:
#include <iostream>

int main()
{
std::cout << "Write */ to close a comment block\n";
}

And then you comment it out like this:

#include <iostream>

int main()
{
/*
std::cout << "Write */ to close a comment block\n";
*/
}
Dec 26 '07 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by KInd | last post: by
7 posts views Thread by Alfonso Morra | last post: by
10 posts views Thread by Philip Ronan | last post: by
10 posts views Thread by nimmi_srivastav | last post: by
8 posts views Thread by Robert W. | last post: by
2 posts views Thread by Bob Day | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.