nesting coments

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

    nesting coments

    I have a question for the sages here.

    the comp.lang.c faq says:

    20.20: Why don't C comments nest? Are they legal inside quoted
    strings?

    A: C comments don't nest because PL/I's comments don't either. The
    character sequences /* and */ are not special within double-
    quoted strings.


    so what is the reason for the latter mentioned language
    to not nest comments? Was it purely a design choice?
    i.e., it wasn't that it was difficult to implement
    it was just horribly ugly?

    I, myself, wouldn't want nested comments because
    it opens doors for allowing unnecessary cluttering
    and conflation. But I'm curious as to the actual reason
    behind disallowing it.



    --
    nethlek
  • Leor Zolman

    #2
    Re: nesting coments

    On 8 Apr 2004 16:04:31 -0700, nethlek@tokyo.c om (Mantorok Redgormor) wrote:
    [color=blue]
    >I have a question for the sages here.
    >
    >the comp.lang.c faq says:
    >
    >20.20: Why don't C comments nest? Are they legal inside quoted
    > strings?
    >
    >A: C comments don't nest because PL/I's comments don't either. The
    > character sequences /* and */ are not special within double-
    > quoted strings.
    >
    >
    >so what is the reason for the latter mentioned language
    >to not nest comments? Was it purely a design choice?
    >i.e., it wasn't that it was difficult to implement
    >it was just horribly ugly?
    >
    >I, myself, wouldn't want nested comments because
    >it opens doors for allowing unnecessary cluttering
    >and conflation. But I'm curious as to the actual reason
    >behind disallowing it.[/color]

    To quickly nip "runaway" comments in the bud? Personally, I always wanted
    to be able to use nested comments, so I believe I had BDS C support them
    (it is amazing how many specific features of that compiler I cannot
    remember precisely). But at the same time (or at least soon after folks
    began complaining), I included a diagnostic pointing to the /start/ of the
    outer-level runaway comment if the compiler reached EOF and was still
    within a comment. Without that diagnostic ability, the "feature" would have
    been a nightmare...
    -leor


    --
    Leor Zolman --- BD Software --- www.bdsoft.com
    On-Site Training in C/C++, Java, Perl and Unix
    C++ users: Download BD Software's free STL Error Message Decryptor at:
    An STL Error Decryptor for C++ by Leor Zolman of BD Software - available to download here

    Comment

    • CBFalconer

      #3
      Re: nesting coments

      Mantorok Redgormor wrote:[color=blue]
      >[/color]
      .... snip ...[color=blue]
      >
      > I, myself, wouldn't want nested comments because it opens doors
      > for allowing unnecessary cluttering and conflation. But I'm
      > curious as to the actual reason behind disallowing it.[/color]

      Probably because back in pre-historic times it was much easier to
      parse. We read the sequence "/*", discard it, and read source
      until the sequence "*/" appears, returning a single blank. No
      need to count things, save things, whatever.

      It remains easier to parse.

      --
      Chuck F (cbfalconer@yah oo.com) (cbfalconer@wor ldnet.att.net)
      Available for consulting/temporary embedded and systems.
      <http://cbfalconer.home .att.net> USE worldnet address!


      Comment

      • Martin Dickopp

        #4
        Re: nesting coments

        Leor Zolman <leor@bdsoft.co m> writes:
        [color=blue]
        > Personally, I always wanted to be able to use nested comments,[/color]

        Why? What would you possibly want to say in a comment (i.e. in an
        explanatory text) that requires nested comments?

        The only reason I can see why one would nest comments is to temporarily
        "comment out" code sections. For that, I prefer #if 0 ... #endif, which
        does nest.

        Martin


        --
        ,--. Martin Dickopp, Dresden, Germany ,= ,-_-. =.
        / ,- ) http://www.zero-based.org/ ((_/)o o(\_))
        \ `-' `-'(. .)`-'
        `-. Debian, a variant of the GNU operating system. \_/

        Comment

        • Leor Zolman

          #5
          Re: nesting coments

          On Fri, 09 Apr 2004 09:54:55 +0200, Martin Dickopp
          <expires-2004-05-31@zero-based.org> wrote:
          [color=blue]
          >Leor Zolman <leor@bdsoft.co m> writes:
          >[color=green]
          >> Personally, I always wanted to be able to use nested comments,[/color]
          >
          >Why? What would you possibly want to say in a comment (i.e. in an
          >explanatory text) that requires nested comments?
          >
          >The only reason I can see why one would nest comments is to temporarily
          >"comment out" code sections. For that, I prefer #if 0 ... #endif, which
          >does nest.[/color]

          Well, /I/ prefer commenting out code sections with comments while
          debugging...les s typing, more intuitive to me. Your mileage obviously
          varies. Note that I don't prefer it /enough/ to go throwing compiler
          switches now in order to have it supported. I just use C++ comments
          everywhere...so I can temporarily comment out at least one non-nested
          section when necessary using C comments.

          I grumble when code I've copied-and-pasted from a newsgroup post has C
          comments and I need to comment out a section ;-)
          -leor
          [color=blue]
          >
          >Martin[/color]

          --
          Leor Zolman --- BD Software --- www.bdsoft.com
          On-Site Training in C/C++, Java, Perl and Unix
          C++ users: Download BD Software's free STL Error Message Decryptor at:
          An STL Error Decryptor for C++ by Leor Zolman of BD Software - available to download here

          Comment

          • Leor Zolman

            #6
            Re: nesting coments

            On Fri, 09 Apr 2004 07:06:13 GMT, CBFalconer <cbfalconer@yah oo.com> wrote:
            [color=blue]
            >Mantorok Redgormor wrote:[color=green]
            >>[/color]
            >... snip ...[color=green]
            >>
            >> I, myself, wouldn't want nested comments because it opens doors
            >> for allowing unnecessary cluttering and conflation. But I'm
            >> curious as to the actual reason behind disallowing it.[/color]
            >
            >Probably because back in pre-historic times it was much easier to
            >parse. We read the sequence "/*", discard it, and read source
            >until the sequence "*/" appears, returning a single blank. No
            >need to count things, save things, whatever.
            >
            >It remains easier to parse.[/color]
            But not by much, and the resources saved on contemporary systems would have
            to be described as infinitesimal.

            As I recall, when that BDS C user complained about the "unexpected EOF"
            message early versions of the compiler gave as a result of runaway
            comments, it took me all of an hour or so to add the smarter diagnostic
            capability (and most of that was waiting for the assembler to churn through
            several debug cycles.) Afterwards I felt like an idiot for not having
            thought of doing that in the first place. I must not have written any test
            programs with runaway comments.
            -leor


            --
            Leor Zolman --- BD Software --- www.bdsoft.com
            On-Site Training in C/C++, Java, Perl and Unix
            C++ users: Download BD Software's free STL Error Message Decryptor at:
            An STL Error Decryptor for C++ by Leor Zolman of BD Software - available to download here

            Comment

            • CBFalconer

              #7
              Re: nesting coments

              Leor Zolman wrote:[color=blue]
              >[/color]
              .... snip ...[color=blue]
              >
              > I grumble when code I've copied-and-pasted from a newsgroup post
              > has C comments and I need to comment out a section ;-)[/color]

              I grumble AND BITCH when such code has C++ comments, illegal under
              C89, and even worse, wrapped during posting.

              --
              Churchill and Bush can both be considered wartime leaders, just
              as Secretariat and Mr Ed were both horses. - James Rhodes.


              Comment

              • Leor Zolman

                #8
                Re: nesting coments

                On Fri, 09 Apr 2004 14:47:28 GMT, CBFalconer <cbfalconer@yah oo.com> wrote:
                [color=blue]
                >Leor Zolman wrote:[color=green]
                >>[/color]
                >... snip ...[color=green]
                >>
                >> I grumble when code I've copied-and-pasted from a newsgroup post
                >> has C comments and I need to comment out a section ;-)[/color]
                >
                >I grumble AND BITCH when such code has C++ comments, illegal under
                >C89, and even worse, wrapped during posting.[/color]

                I /have/ been trying to remember to use only C comments here in clc, in
                deference to folks having (or choosing) to use compilers (or settings) that
                don't support the C++-style comments. And yes, the wrapping /is/ a total
                pain in the ass, I must agree.

                But this does still seem to be a case of irresistable force meets immovable
                object...
                -leor


                --
                Leor Zolman --- BD Software --- www.bdsoft.com
                On-Site Training in C/C++, Java, Perl and Unix
                C++ users: Download BD Software's free STL Error Message Decryptor at:
                An STL Error Decryptor for C++ by Leor Zolman of BD Software - available to download here

                Comment

                • Leor Zolman

                  #9
                  [OT] Re: nesting coments

                  On Fri, 09 Apr 2004 14:47:28 GMT, CBFalconer <cbfalconer@yah oo.com> wrote:
                  [color=blue]
                  >Leor Zolman wrote:[color=green]
                  >>[/color]
                  >... snip ...[color=green]
                  >>
                  >> I grumble when code I've copied-and-pasted from a newsgroup post
                  >> has C comments and I need to comment out a section ;-)[/color]
                  >
                  >I grumble AND BITCH when such code has C++ comments, illegal under
                  >C89, and even worse, wrapped during posting.[/color]

                  BTW, I cracked up over your Mr. Ed sig on that message...and finally
                  realized the value of that funky "-- " sig separator as I tried to reply
                  and include the quote in my response ;-)
                  -leor


                  --
                  Leor Zolman --- BD Software --- www.bdsoft.com
                  On-Site Training in C/C++, Java, Perl and Unix
                  C++ users: Download BD Software's free STL Error Message Decryptor at:
                  An STL Error Decryptor for C++ by Leor Zolman of BD Software - available to download here

                  Comment

                  • Peter Pichler

                    #10
                    Re: nesting coments

                    "Mantorok Redgormor" <nethlek@tokyo. com> wrote in message
                    news:41ec7ac0.0 404081504.10da0 df@posting.goog le.com...[color=blue]
                    > I have a question for the sages here.
                    >
                    > the comp.lang.c faq says:
                    >
                    > 20.20: Why don't C comments nest? Are they legal inside quoted
                    > strings?[/color]

                    Just an observation: this is the first time I see this "frequently asked
                    question" actually asked.

                    Peter


                    Comment

                    • Leor Zolman

                      #11
                      Re: nesting coments

                      On Fri, 9 Apr 2004 17:38:53 +0100, "Peter Pichler" <pichlo7@pobox. sk>
                      wrote:
                      [color=blue]
                      >"Mantorok Redgormor" <nethlek@tokyo. com> wrote in message
                      >news:41ec7ac0. 0404081504.10da 0df@posting.goo gle.com...[color=green]
                      >> I have a question for the sages here.
                      >>
                      >> the comp.lang.c faq says:
                      >>
                      >> 20.20: Why don't C comments nest? Are they legal inside quoted
                      >> strings?[/color]
                      >
                      >Just an observation: this is the first time I see this "frequently asked
                      >question" actually asked.[/color]

                      So that implies either that it isn't really an FA'd Q, or that we have new
                      posters quivering in their boots about posting Q's from the FAQ and
                      everyone has read the answer there already... (NOT!)
                      -leor
                      [color=blue]
                      >
                      >Peter
                      >[/color]

                      --
                      Leor Zolman --- BD Software --- www.bdsoft.com
                      On-Site Training in C/C++, Java, Perl and Unix
                      C++ users: Download BD Software's free STL Error Message Decryptor at:
                      An STL Error Decryptor for C++ by Leor Zolman of BD Software - available to download here

                      Comment

                      • Joe Wright

                        #12
                        Re: nesting coments

                        Leor Zolman wrote:

                        [ snip all ]

                        What would be the harm in a compiler allowing and supporting nested
                        comments? Even though Standard C doesn't support it, is a conforming
                        compiler required to diagnose it as an error?

                        But now that I think about it, nesting comments doesn't make sense. In
                        fact we probably use the term 'comment' badly and abuse its intent. What
                        do we think when we 'comment out' parts of our program? We are not
                        making a comment, we are trying to hide the stuff from the compiler.

                        At least two methods for hiding code come immediately to mind.

                        #if 0
                        ...hidden code..
                        #endif

                        and

                        if (0) {
                        ..hidden code..
                        }

                        Both methods can be nested.

                        Note that the ..hidden code.. is still parsed by the compiler. Syntax
                        and other errors are checked and reported. You can't put free-form text
                        in there the way you do with comments.
                        --
                        Joe Wright mailto:joewwrig ht@comcast.net
                        "Everything should be made as simple as possible, but not simpler."
                        --- Albert Einstein ---

                        Comment

                        • Peter Pichler

                          #13
                          Re: nesting coments

                          "Joe Wright" <joewwright@com cast.net> wrote in message
                          news:bOydnYaoAd evR-vdRVn-vw@comcast.com. ..
                          [color=blue]
                          > #if 0
                          > ..hidden code..
                          > #endif[/color]

                          <snip>
                          [color=blue]
                          > Note that the ..hidden code.. is still parsed by the compiler. Syntax
                          > and other errors are checked and reported. You can't put free-form text
                          > in there the way you do with comments.[/color]

                          A minor correction: it is parsed by the /preprocessor/. Syntax and other
                          errors are /not/ checked and reported, provided they form valid
                          preprocessor tokens. Your last sentence is true, though.

                          Peter


                          Comment

                          • Leor Zolman

                            #14
                            Re: nesting coments

                            On Fri, 09 Apr 2004 13:15:53 -0400, Joe Wright <joewwright@com cast.net>
                            wrote:
                            [color=blue]
                            >Leor Zolman wrote:
                            >
                            >[ snip all ]
                            >
                            >What would be the harm in a compiler allowing and supporting nested
                            >comments? Even though Standard C doesn't support it, is a conforming
                            >compiler required to diagnose it as an error?
                            >
                            >But now that I think about it, nesting comments doesn't make sense.[/color]

                            Not for code you wish to release, of course not.
                            [color=blue]
                            > In
                            >fact we probably use the term 'comment' badly and abuse its intent. What
                            >do we think when we 'comment out' parts of our program? We are not
                            >making a comment, we are trying to hide the stuff from the compiler.[/color]

                            Precisely. In my case, for debugging purposes.
                            [color=blue]
                            >
                            >At least two methods for hiding code come immediately to mind.
                            >
                            >#if 0
                            >..hidden code..
                            >#endif
                            >
                            >and
                            >
                            >if (0) {
                            > ..hidden code..
                            >}
                            >
                            >Both methods can be nested.[/color]

                            And both are a pain compared to simply commenting out sections of code;
                            say, if you're trying to play with two alternate forms of a construct, and
                            don't wish to have to go "formalize" the process with a preprocessor
                            symbol, etc. etc. ad nauseam.
                            [color=blue]
                            >
                            >Note that the ..hidden code.. is still parsed by the compiler.[/color]

                            In the scenarios I'm talking about, that's /not/ what I want!
                            [color=blue]
                            >Syntax
                            >and other errors are checked and reported. You can't put free-form text
                            >in there the way you do with comments.[/color]

                            With nested comments, I can have any ole' broken, half-baked code in there,
                            and that's exactly what I /do/ want to be able to have in there.
                            -leor




                            --
                            Leor Zolman --- BD Software --- www.bdsoft.com
                            On-Site Training in C/C++, Java, Perl and Unix
                            C++ users: Download BD Software's free STL Error Message Decryptor at:
                            An STL Error Decryptor for C++ by Leor Zolman of BD Software - available to download here

                            Comment

                            • Eric Sosman

                              #15
                              Re: nesting coments

                              Joe Wright wrote:[color=blue]
                              >
                              > Leor Zolman wrote:
                              >
                              > [ snip all ]
                              >
                              > What would be the harm in a compiler allowing and supporting nested
                              > comments? Even though Standard C doesn't support it, is a conforming
                              > compiler required to diagnose it as an error?[/color]

                              The compiler is not required to issue a diagnostic when
                              `/*' appears inside a comment, if that's what you mean. On
                              the other hand, the compiler must diagnose `/* /* */ */'
                              because the comment ends at the first `*/', and the second
                              `*/' is a syntax error.

                              With C99, of course, nested comments are perfectly legal:

                              /* This is an outer comment ...
                              // ... containing a nested comment ...
                              ... and then the outer comment continues */

                              However, the use of the term "nested" is debatable here.

                              It's possible to concoct valid sources that somewhat
                              resemble nested comments, e.g.

                              int i = 1
                              /* outer comment
                              /* inner comment */
                              *//
                              0;

                              .... whose effect is the same as `int i = 0;'.

                              --
                              Eric.Sosman@sun .com

                              Comment

                              Working...