nested comments

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rahul

    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!!!
  • yanlinlin

    #2
    Re: nested comments

    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.

    Comment

    • simplyamit2

      #3
      Re: nested comments

      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

      Comment

      • Rolf Magnus

        #4
        Re: nested comments

        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.

        Comment

        • Rahul

          #5
          Re: nested comments

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

          Comment

          • Kira Yamato

            #6
            Re: nested comments

            On 2007-12-26 06:57:14 -0500, Rahul <sam_cit@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

            Comment

            • Dave Rahardja

              #7
              Re: nested comments

              On 2007-12-26 02:06:00 -0600, Rahul <sam_cit@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


              Comment

              • Rahul

                #8
                Re: nested comments

                On Dec 26, 8:07 pm, Dave Rahardja
                <drahardja.plac e...@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...

                Comment

                • =?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=

                  #9
                  Re: nested comments

                  On 2007-12-26 18:02, Rahul wrote:
                  On Dec 26, 8:07 pm, Dave Rahardja
                  <drahardja.plac e...@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

                  Comment

                  • Jack Klein

                    #10
                    Re: nested comments

                    On Wed, 26 Dec 2007 00:06:00 -0800 (PST), Rahul <sam_cit@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.l earn.c-c++

                    Comment

                    • Juha Nieminen

                      #11
                      Re: nested comments

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

                      Comment

                      Working...