home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.lang.c:12459 gnu.gcc.help:1923
- Newsgroups: comp.lang.c,gnu.gcc,gnu.gcc.help
- Path: sparky!uunet!think.com!spdcc!dirtydog.ima.isc.com!karl
- From: karl@ima.isc.com (Karl Heuer)
- Subject: Re: gcc-cpp chokes: bug or feature?
- Message-ID: <1992Aug18.032513.28768@ima.isc.com>
- Sender: usenet@ima.isc.com (news)
- Organization: Interactive Systems, Cambridge, MA 02138-5302
- References: <BszKpr.GBu@cs.columbia.edu>
- Date: Tue, 18 Aug 1992 03:25:13 GMT
- Lines: 42
-
- In article <BszKpr.GBu@cs.columbia.edu> leland@cs.columbia.edu (Leland Woodbury) writes:
- >Why is it parsing what should be getting ifdef'd out?
-
- /* example #1 */
- #if 0
- /*
- #else
- /* */
- printf("hello\n");
- #endif
- Does the preprocessor ignore everything between #if 0 and #else, in which
- case the printf() is active (since it's between the #else and #endif)? Or is
- `/* #else /* */' merely a comment, in which case the printf() is inactive?
-
- Answer: Both Classic C and ANSI C use the latter interpretation. Hence the
- preprocessor must do lexing of comments, even inside if'd out sections.
-
- /* example #2 */
- #if 0
- "\
- #else /*"/**/
- printf("hello\n");
- #endif
-
- This case is similar: the #if'd block contains a string literal (which happens
- to include a continuation line), a comment (which happens to include an
- embedded `/*'), and a printf(). It does not include an #else. Again, Classic
- C and ANSI C agree on this.
-
- So you see, the preprocessor has always done lexical analysis within #if'd
- blocks, even in Classic C. It happens that the Reiser preprocessor, when
- it encountered an unescaped newline inside a string literal or character
- constant, would silently close the quotes. This was one of several
- arbitrary decisions that were documented in the preamble to the cpp source.
- (Fascinating reading; I didn't realize how many loopholes there were in the
- informal K&R specification.) ANSI C did not require this particular quirk,
- and the GNU people chose to produce a diagnostic for it instead.
-
- I personally prefer the diagnostic. I don't like having compilers play "guess
- what I'm thinking, and compile it".
-
- Karl W. Z. Heuer (karl@ima.isc.com or uunet!ima!karl), The Walking Lint
-