One of the questions posed in 8th mile OSP prelims was :
Write a program to check if the compiler (C compiler ) allows nested comments.
Here is the solution I came up with
#include<stdio.h>
int main()
{
int i=10,*j,k,l=20;
j=&l;
k= /* /* */i */*j;/* */ 1;
if(k==i)
printf(”does not allow nested comments\n”);
else if(k==l)
printf(”allows nested comments”);
return 0;
}
I hope it works.. Comments and suggestions are most welcome. Please tell me if u have a better solution.
Debarshi Ray said,
April 6, 2008 at 1:57 am
Here is a C and a C++ version:
http://rishi.fedorapeople.org/comments.c.html
http://rishi.fedorapeople.org/comments.cpp.html
Have you found a compiler that does support nested comments? I want to try out my programs on such a compiler. Till now I have tried GCC and Sun’s proprietary CC, but none of them support nested comments.
Netra said,
April 6, 2008 at 3:07 pm
Hi Debarshi.. Nice links. I dont know about any compiler that supports nested comments but the question was to check if the compiler supports nested comments. So in case such a compiler exists this program must give me the right output
Prabhanjan said,
April 6, 2008 at 3:47 pm
great job once again ….
Bharath said,
June 2, 2008 at 10:00 pm
Ah! Thanks a ton for posting this one..Wonderful job done, I have been looking out for methods. But sadly, i have not been able to implement the code on a compiler that allows nested comments(Is there any?)
Bharath said,
June 2, 2008 at 10:06 pm
And yeah..the solution is lexically perfect!..
God Bless!
Netra said,
June 3, 2008 at 1:31 pm
Thats very kind of you.. Thank you Bharath
Timmy said,
June 5, 2008 at 5:39 pm
Cool!.. Nice work…o