Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!wasatch!helios.ee.lbl.gov!pasteur!ames!uhccux!munnari.oz.au!mimir!hugin!augean!sirius!scott From: scott@cs.ua.oz.au (Scott Davis) Newsgroups: comp.lang.c++ Subject: Re: "//" comments and #define's : problems Message-ID: Date: 21 Jul 89 07:27:20 GMT References: <1000019@hpclscu.HP.COM> Sender: news@sirius.ua.oz Organization: Computer Science, Adelaide University, Australia Lines: 60 In-reply-to: shankar@hpclscu.HP.COM's message of 11 Jul 89 17:06:50 GMT In article <1000019@hpclscu.HP.COM> shankar@hpclscu.HP.COM (Shankar Unni) writes: > 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). > > [further discussion of problem] > > 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 > > This is one more reason to adopt a *standard* cpp (preferably an ANSI C > style cpp), with well-defined "//"-comment semantics. > What about: (d) Insert the carriage return which terminates the comment as well, as in x b // comment y OK, so this doesn't look quite the same, but at least it is semantically correct, and the comments *are* still there if you want to read them. This is the method I would expect, as the comment is terminated by end of line, it doesn't just fade off to some indeterminate point. The Carriage return is as much a part of the comment as the '//' which started it. You don't strip off the */ from the end of a C-style comment, just leaving the /* at the beginning, so why treat C++-style comments any different? Comments? Scott. -- Scott Davis ACSnet: scott@cs.ua.oz{.au} Honours student, other: scott@cs.ua.oz@uunet.uu.net Department of Computer Science, University of Adelaide. Australia. -- Scott Davis ACSnet: scott@cs.ua.oz{.au} Honours student, other: scott@cs.ua.oz@uunet.uu.net Department of Computer Science, University of Adelaide.