nested comments

R

Rahul

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!!!
 
Y

yanlinlin

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.
 
S

simplyamit2

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
 
R

Rolf Magnus

Rahul said:
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.
 
R

Rahul

Mostly because the language definition says so, I guess.





Maybe because there is no need for it.

well, sometimes i does make sense to properly align the comments...
 
D

Dave Rahardja

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
 
R

Rahul

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...
 
E

Erik Wikström

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.
 
J

Jack Klein

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
 
J

Juha Nieminen

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";
*/
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top