chris@cs.hw.AC.UK (Chris Miller) (06/04/86)
[ 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
gwyn@brl-smoke.ARPA (Doug Gwyn ) (06/15/86)
In article <839@brahma.cs.hw.AC.UK> chris@cs.hw.AC.UK (Chris Miller) writes:
- #if ('j' - 'i' == 1)
-...
-The evaluation of the constant expression is clearly intended to be carried
-out in terms of the "execution environment" rather than the "translation
-environment".
Well, that's a bug on the part of the programmer.
The C translator is permitted to evaluate preprocessor
expressions using the native facilities, even when
cross-compiling.