Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!cs.utexas.edu!ginosko!uunet!munnari.oz.au!cs.mu.oz.au!ok From: ok@cs.mu.oz.au (Richard O'Keefe) Newsgroups: comp.lang.c Subject: Re: This one bit me today Message-ID: <2509@munnari.oz.au> Date: 24 Oct 89 09:20:32 GMT References: <2432@hub.UUCP> <568@sppy00.UUCP> <750@philmtl.philips.ca> <41019@bu-cs.BU.EDU> Sender: news@cs.mu.oz.au Lines: 58 In article <41019@bu-cs.BU.EDU>, austin@bucsf.bu.edu (Austin Ziegler) writes: > I read the rest of your article, but this is the one part I have > problems with. I am originally a Pascal programmer, and have been > programming in C for enough time to acquaint myself with the language. In > Pascal, one of the nicest features for debugging is nested comments. Er, there's something your best friend should have told you: Pascal comments DO NOT NEST. Neither in the ANSI standard, nor the ISO standard, nor Jensen & Wirth, nor either of the Pascal compilers I just checked (although one of them prints a warning if it sees '(*' inside '(*'). Here is a Pascal program. | program nestcom(input, output); | begin | (* comments in Pascal do not nest: | (* this is not a nested comment *) | writeln('This is not commented out'); | (* this is not a nested comment *) | writeln('This *) does not close any comment'); | end (* nestcom *). Compiling and running this program produces the output | This is not commented out | This *) does not close any comment A Pascal processor which conforms to the standard may still have trouble with it (the output lines might be too long or it might not support lower case or something), but modulo case this is the only valid output from it. Any Pascal processor which treats these comments as nested VIOLATES THE STANDARD. > I *have* found the need to > comment it out because I am not fully acquainted with all of the features > of the preprocessor commands. The only preprocessor directives you need to know are #if 0 #endif It is extremely important to realise that nested comments are "pushed" as a debugging tool, BUT THEY DO NOT WORK RELIABLY FOR THAT PURPOSE. If the code you are commenting out contains comment delimiters, putting nested comment delimiters around it is going to land you in big trouble. A UNIX C programmer might be likely to call f = popen("ls SCCS/*.p", "r"); ^^ If you have an Emacs-like editor, it is extremely easy to write a comment-out-region command which works just fine without needing nested comments. Mine turns /* into /* and similarly for */, comment-in-region decrements the number of spaces and removes the outer delimiter pair. > I *AM* a Pascal guru, when I want to be. Pascal gurus have memorized the Standard.