Topic: Another #define question


Author: Carlo Wood <carlo@alinoe.com>
Date: Sun, 31 Dec 2000 04:25:26 GMT
Raw View
Hi, I am writing a C++ source code analyzer
therefore the following question:

Is this legal or illegal C++?

#define QUOTE "

It seems legal to me because the replacement-list
in this case is a single quote, which can't be a
string-literal (because those are not allowed to
contain new-lines) but is a non-white-space
character.  A preprocessing token is allowed to be
"any non-white-character that cannot be one of
the above" (see my previous post, or Annex A in the
C++ standard), I'd think that includes a single
double quote.

I know of at least one compiler that thinks the
above is a syntax error however.  Is it?

--
Carlo Wood <usenet@nospam.alinoe.com>

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]





Author: Stephen Clamage <stephen.clamage@sun.com>
Date: Tue, 2 Jan 2001 01:56:13 GMT
Raw View
On Sun, 31 Dec 2000 04:25:26 GMT, Carlo Wood <carlo@alinoe.com> wrote:

>Is this legal or illegal C++?
>
>#define QUOTE "
>
>It seems legal to me because the replacement-list
>in this case is a single quote, which can't be a
>string-literal (because those are not allowed to
>contain new-lines) but is a non-white-space
>character.  A preprocessing token is allowed to be
>"any non-white-character that cannot be one of
>the above" (see my previous post, or Annex A in the
>C++ standard), I'd think that includes a single
>double quote.

No. Refer to 2.4 paragraph 1, and notice that by itself, a " character
is not a preprocessing operator or punctuator. It can only introduce
(or terminate) a string literal.

---
Steve Clamage, stephen.clamage@sun.com

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]





Author: wmm@fastdial.net
Date: Tue, 2 Jan 2001 21:55:01 GMT
Raw View
In article <oar15tgut4enei9cd5vsd5nia0cudlc286@4ax.com>,
  stephen.clamage@sun.com wrote:
> On Sun, 31 Dec 2000 04:25:26 GMT, Carlo Wood <carlo@alinoe.com> wrote:
>
> >Is this legal or illegal C++?
> >
> >#define QUOTE "
> >
> >It seems legal to me because the replacement-list
> >in this case is a single quote, which can't be a
> >string-literal (because those are not allowed to
> >contain new-lines) but is a non-white-space
> >character.  A preprocessing token is allowed to be
> >"any non-white-character that cannot be one of
> >the above" (see my previous post, or Annex A in the
> >C++ standard), I'd think that includes a single
> >double quote.
>
> No. Refer to 2.4 paragraph 1, and notice that by itself, a " character
> is not a preprocessing operator or punctuator. It can only introduce
> (or terminate) a string literal.

More to the point is 2.4p2:

    If a     or a " character matches the last category, the
    behavior is undefined.

(where "the last category" refers to the "any non-white-space
character that cannot be one of the above" catch-all).

That means that a compiler is within its rights to issue an
error message for such code, but need not do so if the
implementor found that easier or preferable.

--
William M. Miller, wmm@fastdial.net
Vignette Corporation (www.vignette.com)


Sent via Deja.com
http://www.deja.com/

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]