Re: Pre-Parsers (Fergus Henderson)
10 Oct 2000 13:00:41 -0400

          From comp.compilers

Related articles
Pre-Parsers (Jim Granville) (2000-09-08)
Re: Pre-Parsers (Randall Hyde) (2000-09-09)
Re: Pre-Parsers (2000-09-13)
Re: Pre-Parsers (2000-09-15)
Re: Pre-Parsers (2000-09-21)
Re: Pre-Parsers (Hans-Bernhard Broeker) (2000-10-08)
Re: Pre-Parsers (2000-10-10)
Re: Pre-Parsers (2000-10-12)
Re: Pre-Parsers (2000-10-12)
| List of all articles for this month |

From: (Fergus Henderson)
Newsgroups: comp.compilers
Date: 10 Oct 2000 13:00:41 -0400
Organization: Computer Science, University of Melbourne
References: 00-09-119 00-09-155 00-10-044
Keywords: practice, C

Hans-Bernhard Broeker <> writes:

>[someone wrote:
>> #if sizeof(int)==2 ...
>> Here sizeof() must be evaluated by the preprocessor.
>'Must' is debatable, here. With equal justification, one could say
>that source that contains such lines 'must' be rejected for being
>incompatible with the definition of the language it's supposed to be
>written in...

and our moderator replies:

>[What definition would that be? ANSI/ISO C certainly permits sizeof in
>preprocessor expressions. -John]

ANSI/ISO C permits the identifier `sizeof' in preprocessor expressions,
but the standard says it must not be treated as a keyword. If it is
a macro, it must be expanded, and otherwise, it must be replaced with `0'.
The same applies to the other identifier `int' in that source code.
If neither `sizeof' nor `int' are defined as macros, the condition must
expand to `0(0)==2', which is a syntax error, and so the
implementation must report a diagnostic.

The main reason for this is to allow the C preprocessor to be
implemented as completely separate pass from the C compiler, since
that is the way it was traditionally done. Some C compilers which
have an integrated preprocessor do support `sizeof' and such like
in `#if' conditions, as an (incompatible) extension to standard C.

Fergus Henderson <> | "I have always known that the pursuit
WWW: <> | of excellence is a lethal habit"
PGP: finger fjh@ | -- the last words of T. S. Garp.
[Oops. Sorry about that. -John]

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.