Path: utzoo!attcan!uunet!tut.cis.ohio-state.edu!snorkelwacker!think!zaphod.mps.ohio-state.edu!mips!bridge2!jarthur!mti!adrian From: adrian@mti.mti.com (Adrian McCarthy) Newsgroups: comp.lang.c Subject: Re: Why nested comments not allowed? Message-ID: <912@mti.mti.com> Date: 22 Feb 90 17:55:24 GMT References: <236100027@prism> <7060002@hpfcso.HP.COM> Reply-To: adrian@mti.UUCP (Adrian McCarthy) Organization: Micro Technology, Anaheim, CA Lines: 30 In article <7060002@hpfcso.HP.COM> mike@hpfcso.HP.COM (Mike McNelly) writes: > > > I'm just curious to know why nested comments are not allowed in many > > languages. > >1. They have limited usefulness. For most of the occasions where they >are useful, conditional compilation seems to work better. In C, for >example, Often, while developing a program, it is useful to comment out a section of code. Using conditional compilation for this is about as clumsy as using nested comments. Sometimes you want to comment out *part* of a line, but that is awkward since #ifdef must be at the beginning of a line. When you want to comment out larger chunks of code, the #ifdef - #endif lines are easy to loose site of (especially if your code has lots of #ifdef's for other reasons). On top of all that, not all languages have preprocessors. In practice, it seems we don't really need true nested comments, but simply two kinds of comments: regular comments and code omitting comments. It seems Pascal almost had it right. You could use "{" and "}" to delimit regular comments, and "(*" and "*)" to comment out code. Alas, most implementations of Pascal will allow a "*)" to end a comment introduced by "{". Aid. P.S. I'm working on a macro preprocessor that, unlike the C preprocessor and m4, will be useful on nearly all types of source code *and* documentation. In its default mode, it is an ANSI compliant C preprocessor. Don't hold your breath though; it'll be awhile before it's done.