Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!panda!husc6!harvard!seismo!mcvax!ukc!cstvax!hwcs!chris From: chris@cs.hw.AC.UK (Chris Miller) Newsgroups: net.lang.c Subject: Re: C Preprocessor Message-ID: <839@brahma.cs.hw.AC.UK> Date: Wed, 4-Jun-86 07:06:30 EDT Article-I.D.: brahma.839 Posted: Wed Jun 4 07:06:30 1986 Date-Received: Sun, 8-Jun-86 06:21:59 EDT References: <989@dataioDataio.UUCP> <2600061@ccvaxa> Reply-To: chris@cs.hw.AC.UK (Chris Miller) Organization: Computer Science, Heriot-Watt U., Scotland Lines: 47 [ The context is a discussion of whether implementing the C Preprocessor as a separate program, such as /lib/cpp on Unix, is desirable ] In article <2600061@ccvaxa> aglew@ccvaxa.UUCP (Andy Glew) writes: >Unfortunately, there is no longer a clean conceptual break between >the C pre-processor and the compiler: `sizeof' can be used in >pre-processor constant-expressions. The latter part of the above is untrue according to the ANSI draft of February 1986 (Section C.8.1): "Additional restrictions apply to a constant expression that controls conditional inclusion: The expression shall not contain a 'sizeof' operator, a cast, or an enumeration constant." The intention is clearly to enable the pre-processing to be done without knowledge of C type semantics, nor of type implementation details on particular target machines. However, there is a subtle point that makes it necessary that the preprocessor know *something* about the target machine: consider #if ('j' - 'i' == 1) char conv[] = { ... }; /* ASCII conversion table */ #else char conv[] = { ... }; /* EBCDIC conversion table */ #endif or #if (-1 == ~0) /* 2s complement code */ #else /* 1s complement or sign&magnitude code */ #endif The evaluation of the constant expression is clearly intended to be carried out in terms of the "execution environment" rather than the "translation environment". Hence the preprocessor must know about (in this case) the target's character set and integer arithmetic implementation. This is not necessarily undesirable, but it does make it difficult to provide a universal implementation of a C preprocessor. -- Chris Miller, Heriot-Watt University, Edinburgh ...!ukc!hwcs!chris chris@hwcs.uucp chris@cs.hw.ac.uk