Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!usc!zaphod.mps.ohio-state.edu!think!snorkelwacker!spdcc!ima!haddock!karl From: karl@haddock.ima.isc.com (Karl Heuer) Newsgroups: comp.lang.c Subject: Re: Why nested comments not allowed? Message-ID: <16023@haddock.ima.isc.com> Date: 26 Feb 90 03:40:09 GMT References: <4015@hub.UUCP> <4550@jarthur.Claremont.EDU> <10837@june.cs.washington.edu> <4601@jarthur.Claremont.EDU> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Cambridge, MA 02138-5302 Lines: 21 In article <4601@jarthur.Claremont.EDU> dfoster@jarthur.Claremont.EDU (Derek R. Foster) writes: >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. [So, when it is desirable to >put them in a string constant, they should be encoded] in some way that >breaks up the /* and */ pairs ... my favorite so far is this: > #define CS "/""* " > #define CE " *""/" > printf("before comment"CS"comment"CE"after comment"); If we're talking about C, then of course this is not necessary since the scanner already knows about strings. Therefore, I assume we're talking about a hypothetical language which is a lot like C, but which has nestable comments and therefore must worry about the interaction between comments and strings. Surely if such a language existed, it would also have the escape sequences `\*' (literal star) and `\/' (literal slash), so you could simply write printf("before comment/\* comment *\/after comment"); (note that `\?' was added to ANSI C for essentially this reason). Karl W. Z. Heuer (karl@ima.ima.isc.com or harvard!ima!karl), The Walking Lint