Re: Pre-Parsers

fjh@cs.mu.OZ.AU (Fergus Henderson)
10 Oct 2000 13:00:41 -0400

          From comp.compilers

Related articles
Pre-Parsers jim.granville@designtools.co.nz (Jim Granville) (2000-09-08)
Re: Pre-Parsers rhyde@cs.ucr.edu (Randall Hyde) (2000-09-09)
Re: Pre-Parsers vbdis@aol.com (2000-09-13)
Re: Pre-Parsers saroj@bear.com (2000-09-15)
Re: Pre-Parsers vbdis@aol.com (2000-09-21)
Re: Pre-Parsers broeker@physik.rwth-aachen.de (Hans-Bernhard Broeker) (2000-10-08)
Re: Pre-Parsers fjh@cs.mu.OZ.AU (2000-10-10)
Re: Pre-Parsers brynjulv.hauksson@sds.no (2000-10-12)
Re: Pre-Parsers jthorn@galileo.thp.univie.ac.at (2000-10-12)
| List of all articles for this month |
From: fjh@cs.mu.OZ.AU (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 <broeker@physik.rwth-aachen.de> 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 <fjh@cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3 | -- 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.