Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: "C's Biggest Mistake" Date: Thu, 12 Apr 2018 15:19:41 -0700 Organization: None to speak of Lines: 58 Message-ID: References: <9c7013a2-17bd-4f94-a378-1c45151d0d45@googlegroups.com> <6zpxC.75432$bz1.69868@fx01.iad> <%6sxC.621528$Ml.294897@fx24.am4> <85txC.105783$q15.11321@fx34.iad> <_MIzC.1013644$Ly1.422539@fx13.am4> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="ea2a9ed0588f04f630d6972f440d2322"; logging-data="2699"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18kTz92jLvx6rIYDZvPwEJQ" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:JqjvsS3h7K82HROjRp1pI9Fa0Ak= sha1:wDwZiLaX9GNks0oBpixTxZgk/KI= Xref: csiph.com comp.lang.c:129113 bartc writes: > On 12/04/2018 21:12, Scott Lurndal wrote: >> Ian Collins writes: >>>> What about this one: >>>> >>>> puts("one"); /* comment one >>>> puts("two"); /* comment two */ > >>> Because the code fails its tests? >>> >> >> Or because they're using an editor with syntax highlighting. > > Syntax highlighting only syntax highlights what's in the editor's > current window. That incomplete comment may be elsewhere, if it gets > created from some global edits, or you don't notice before you scroll to > a different part. I presume the "current window" shows the contents of a single source file. Comments cannot span multiple source files. [...] > Allowing nested /*...*/ comments, while not foolproof, would have picked > up this case in the form of an unmatched /*. The ANSI C committee considered and rejected proposals to allow /*...*/ comments to nest. Allowing them to nest would have caused other problems. For example, as it stands now, the text following "/*" is examined only to find the corresponding "*/". A /* sequence with a string literal does not start a comment. This: /* puts("Does this terminate the comment? */"); */ is currently a syntax error because the first */ terminates the comment. With nested comments, it would be a valid comment -- which would mean that the compiler would have to recognize string literals inside comments. Either that, or it would not recognize string literals, which would mean that nested comments couldn't be used to comment out blocks of code (the main reason for the proposals to allow them). https://www.lysator.liu.se/c/rat/c1.html#3-1-9 Yes, C's comment syntax can cause problems if you're not careful. Most proposals to fix those problems would create more problems than they'd solve. And changing the language to permit nested comments would break existing code, which is unacceptable. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"