Path: utzoo!attcan!uunet!cs.utexas.edu!usc!ucsd!ames!ads.com!sparkyfs!mckenney From: mckenney@sparkyfs.istc.sri.com (Paul Mckenney) Newsgroups: comp.lang.c++ Subject: Re: f***ing comments -- another pitfall to avoid Message-ID: <31891@sparkyfs.istc.sri.com> Date: 25 May 90 17:04:28 GMT References: <1504@trlluna.trl.oz> <69.UUL1.3#5109@pantor.UUCP> <54683@microsoft.UUCP> <0682@sheol.UUCP> <54781@microsoft.UUCP> Reply-To: mckenney@.itstd.sri.com (Paul E. McKenney) Organization: SRI International, Menlo Park, CA 94025 Lines: 42 Even if you have a preprocessor that knows about C++ comments, one must be careful... Consider the following: ------------------------------------------------------------------------ #define commentmacro \ This is // (we interrupt this macro with a comment) \ a test commentmacro ------------------------------------------------------------------------ Doing ``g++ -E'' yields: ------------------------------------------------------------------------ # 1 "commentmacro.cc" a test This is ------------------------------------------------------------------------ Here, the ``//'' has apparently eaten the backslash, thus prematurely terminating the comment. I would prefer to see the ``//'' comment operate up to (but not including) the next newline or the next backslash that is immediately followed by a newline (whichever comes first). This would yield the more intuitive result: ------------------------------------------------------------------------ # 1 "commentmacro1.cc" This is a test ------------------------------------------------------------------------ I guess that the moral of this story is that one should always use the ``/**/'' style comments inside of macro definitions, at least until the ``//'' comments behave more intuitively in mainstream implementations... Thanx, Paul