Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B UNSW 1.0 3/14/84; site elecvax.SUN Path: utzoo!watmath!clyde!burl!ulysses!mhuxl!ihnp4!zehntel!hplabs!tektronix!decvax!mulga!munnari!basser!elecvax!stephenf From: stephenf@elecvax.SUN (Stephen Frede) Newsgroups: net.bugs,net.lang.c Subject: Bug (?) in C preprocessor Message-ID: <204@elecvax.SUN> Date: Mon, 28-May-84 17:20:44 EDT Article-I.D.: elecvax.204 Posted: Mon May 28 17:20:44 1984 Date-Received: Fri, 1-Jun-84 00:01:38 EDT Organization: EE and CS, Uni of NSW, Sydney, Australia Lines: 57 Newsgroups: net.bugs,net.lang.c Subject: Bug (?) in C preprocessor Note the following behaviour of the C preprocessor (V7 and System V): #define FRED jim #define QUOTE(x) "x" QUOTE(FRED) ______________________ The output of the C preprocessor when fed this fragment is "FRED" Obviously, it is applying the QUOTE() macro on FRED, before re-scanning and since "FRED" is then quoted, no substitution takes place. If the order of evaluation were the other way, ie to evaluate what is inside the parentheses first, before applying the macro QUOTE to it, the result would be "jim" (which is actually what I wanted when I discovered this). I suggest that this order of evaluation is more sensible, and conforms more closely to what C itself (and almost all other programming languages) does (evaluating expressions from within the most deeply nested level of parentheses first). I will probably be changing the preprocessor here to do this, but would like to see what the net thinks first. Has anyone else come across this problem? Aside: If this change is made, then it allows constructs like #define QUOTE(x) "x" #include QUOTE(NAME.h) where NAME is defined to the preprocessor on the command line at compile time. Whether this is a terrible thing to do or not is another story. I wanted it so I could modify maketerms.c in the nroff system so that I could make terminal driving tables one at a time (a single "make" at the top of our source directory would then install a new terminal driving table in /usr/lib/terms without having to create a whole set. Also, new driving tables could then be added without modifying maketerms.c. Stephen Frede Dept. Computer Science University of NSW P.O. Box 1 Kensington 2033 AUSTRALIA ...!decvax!mulga!stephenf:elec70b