ugh.book

(singke) #1
Syntax Syrup of Ipecac 209

Date: Sun, 21 May 89 18:02:14 PDT
From: tiemann (Michael Tiemann)
To: [email protected]
Cc: UNIX-HATERS
Subject: C++ Comments


Date: 21 May 89 23:59:37 GMT
From: [email protected] (Scott Meyers)
Newsgroups: comp.lang.c++
Organization: Brown University Dept. of Computer Science

Consider the following C++ source line:

//**********************

How should this be treated by the C++ compiler? The GNU
g++ compiler treats this as a comment-to-EOL followed by a
bunch of asterisks, but the AT&T compiler treats it as a slash
followed by an open-comment delimiter. I want the former
interpretation, and I can’t find anything in Stroustrup’s book
that indicates that any other interpretation is to be expected.

Actually, compiling -E quickly shows that the culprit is the
preprocessor, so my questions are:


  1. Is this a bug in the AT&T preprocessor? If not, why not? If so, will it
    be fixed in 2.0, or are we stuck with it?

  2. Is it a bug in the GNU preprocessor? If so, why?


Scott Meyers
[email protected]

There is an ancient rule for lexing UNIX that the token that should be
accepted be the longest one acceptable. Thus ‘foo’ is not parsed as
three identifiers, ‘f,’ ‘o,’ and ‘o,’ but as one, namely, ‘foo.’ See how
useful this rule is in the following program (and what a judicious
choice ‘/*’ was for delimiting comments):

double qdiv (p, q)
double *p, *q;
{
return *p/*q;
}

So why is the same rule not being applied in the case of C++? Sim-
ple. It’s a bug.

Free download pdf