Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!usc!elroy.jpl.nasa.gov!jarthur!dfoster From: dfoster@jarthur.Claremont.EDU (Derek R. Foster) Newsgroups: comp.lang.c Subject: Re: Re^4: Why nested comments not allowed? Message-ID: <4601@jarthur.Claremont.EDU> Date: 23 Feb 90 21:52:28 GMT References: <4015@hub.UUCP> <4550@jarthur.Claremont.EDU> <10837@june.cs.washington.edu> Organization: Harvey Mudd College, Claremont, CA 91711 Lines: 40 In article <10837@june.cs.washington.edu> machaffi@fred.cs.washington.edu.cs.washington.edu (Scott MacHaffie) writes: >In article <4550@jarthur.Claremont.EDU> dfoster@jarthur.Claremont.EDU (Derek R. Foster) writes: >>The only real reasons there are to do this (put /* or */ in strings) are: > >You forgot "writing a C parser which has to recognize comments". > > Scott MacHaffie No, I didn't. You missed the point of my statement. (Don't feel bad; several other people did too. That's why I'm posting instead of e-mailing you. Most of the criticisms that I have heard have come from people that simply misunderstood what I was saying. Was I really that unclear?) I wasn't saying that these characters should never be used as string data. I said that they should not be placed LITERALLY in a string, since they may be mistaken (by the parser) for comments. (Literally as in, "inside quotation marks, a '*' followed IMMEDIATELY by a '/' or vice versa"). Since the parser will only recognize these characters as a comment if it sees them one right after the other, encoding printf("before comment /* comment */ after comment"); in some way that breaks up the /* and */ pairs (but still means the same thing to the compiler, just not the parser) means that the parser won't ever mistake them for comments. I have posted several suggestions on how to do this, but in case you missed them, my favorite so far is this: #define CS "/""* " #define CE " *""/" . . . printf("before comment"CS"comment"CE"after comment"); Note that although these lines produce code that is functionally identical to the first printf, at no point in the code do the characters '/*' or '*/' appear as literal strings. Therefore, they won't be recognized by the parser as comments, and so won't cause you problems later on. Derek Foster