Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!decwrl!shelby!unix!hplabs!hpda!hpcuhb!hpcllla!hpclisp!hpclscu!shankar From: shankar@hpclscu.HP.COM (Shankar Unni) Newsgroups: comp.lang.c++ Subject: "//" comments and #define's : problems Message-ID: <1000019@hpclscu.HP.COM> Date: 11 Jul 89 17:06:50 GMT Organization: Hewlett-Packard Calif. Language Lab Lines: 53 When fixing up a "cpp" to handle "//"-style comments, I came across an interesting problem. Comments on #define's are preserved by cpp when sucking up the define, and later, after substitution, subsequent rescans of the line simply strip out the comment. (This is how it makes token-pasting, etc work). When the comment is a "//" comment, the following happens: #define a b // comment x a y turns into x b // comment y and then into x b (I.e. the "y" is stripped out). This is an intrinsic problem with "//"-comments on #defines, because if you use the "pass comments" option on cpp (usually -C on sysV-based systems), the same thing will happen (you'll get stage two above, and then cfront will strip out the "y" token). Question: How should a "//"-comment on a #define work? (a) Completely stripped out when processing #define. Not passed through even when requesting "pass comments". (This is my preference). (b) Leave it as is. I.e. specify that a "//"-comment on a #define will have "undefined" (i.e. nasty and unpredictable) effects. Warn the user when detected. (c) Do some fudge like have "cpp" insert a "/*" and "*/" around the "//"-style comment, as in x b /* // comment */ y I'm interested in hearing opinions on this (esp. from AT&T, since they are asking their cfront customers/VARs to provide their own cpp). Shouldn't this be standardized somewhere? This is one more reason to adopt a *standard* cpp (preferably an ANSI C style cpp), with well-defined "//"-comment semantics. ----- Shankar Unni E-Mail: Hewlett-Packard California Language Lab. Internet: shankar@hpda.hp.com Phone : (408) 447-5797 UUCP: ...!hplabs!hpda!shankar