1*7981Srrh# 2*7981Srrh# @(#)README 1.1 08/30/82 3*7981Srrh# 4*7981SrrhAugust 25, 1978 5*7981Srrh 6*7981SrrhFiles in this directory form the C preprocessor, which handles '#include' 7*7981Srrhfiles and macro definition and expansion for the C compiler. 8*7981SrrhThis new version was written by John F. Reiser and is from 5 to 12 9*7981Srrhtimes faster (on UNIX systems) than the old. 10*7981Srrh 11*7981SrrhTo create the executable file 'cpp' in the current directory: 12*7981Srrh make 13*7981Srrh 14*7981SrrhTo install the preprocessor 'cpp' so it will be used by the C compiler: 15*7981Srrh : safety first: backup the existing version 16*7981Srrh cp /lib/cpp /lib/ocpp 17*7981Srrh : install the new version 18*7981Srrh cp cpp /lib/cpp 19*7981Srrh 20*7981SrrhInvocation 21*7981Srrh cpp [-CEPR] [-Dname] ... [-Dname=def] ... [-Idirectory] ... 22*7981Srrh [-Uname] ... [<infile>] [<outfile>] 23*7981Srrh 24*7981Srrh If there are two non-flag arguments then the first is the name of the 25*7981Srrh input file and the second is the name of the output file. If there is 26*7981Srrh one non-flag argument then it is the name of the input file and the 27*7981Srrh output is written on the standard output. If there are no non-flag 28*7981Srrh arguments then the input is taken from the standard input and the output 29*7981Srrh is written on the standard output. Flag arguments are: 30*7981Srrh 31*7981Srrh -C retain comments in output 32*7981Srrh -Dname define name as "1" 33*7981Srrh -Dname=def define name as def 34*7981Srrh -E ignored 35*7981Srrh -Idirectory add directory to search list for #include files 36*7981Srrh -P don't insert lines "# 12 \"foo.c\"" into output 37*7981Srrh -R allow recursive macros 38*7981Srrh -Uname undefine name 39*7981Srrh 40*7981SrrhDocumentation clarifications: 41*7981Srrh Symbols defined on the command line by "-Dfoo" are defined as "1", 42*7981Srrh i.e., as if they had been defined by "#define foo 1" or "-Dfoo=1". 43*7981Srrh The directory search order for #include files is 44*7981Srrh 1) the directory of the file which contains the #include request 45*7981Srrh (e.g. #include is relative to the file being scanned when 46*7981Srrh the request is made) 47*7981Srrh 2) the directories specified by -I, in left-to-right order 48*7981Srrh 3) the standard directory(s) (which for UNIX is /usr/include) 49*7981Srrh An unescaped linefeed (the single character "\n") terminates a 50*7981Srrh character constant or quoted string. 51*7981Srrh An escaped linefeed (the two-character sequence "\\\n") may be 52*7981Srrh used in the body of a '#define' statement to continue 53*7981Srrh the definition onto the next line. The escaped linefeed is 54*7981Srrh not included in the macro body. 55*7981Srrh Comments are uniformly removed (except if the argument -C is specified). 56*7981Srrh They are also ignored, except that a comment terminates a token. 57*7981Srrh Thus "foo/* la di da */bar" may expand 'foo' and 'bar' but 58*7981Srrh will never expand 'foobar'. If neither 'foo' nor 'bar' is a 59*7981Srrh macro then the output is "foobar", even if 'foobar' 60*7981Srrh is defined as something else. The file 61*7981Srrh #define foo(a,b)b/**/a 62*7981Srrh foo(1,2) 63*7981Srrh produces "21" because the comment causes a break which enables 64*7981Srrh the recognition of 'b' and 'a' as formals in the string "b/**/a". 65*7981Srrh Macro formal parameters are recognized in '#define' bodies even inside 66*7981Srrh character constants and quoted strings. The output from 67*7981Srrh #define foo(a) '\a' 68*7981Srrh foo(bar) 69*7981Srrh is the seven characters " '\\bar'". Macro names are not recognized 70*7981Srrh inside character constants or quoted strings during the regular scan. 71*7981Srrh Thus 72*7981Srrh #define foo bar 73*7981Srrh printf("foo"); 74*7981Srrh does not expand 'foo' in the second line, because it is inside 75*7981Srrh a quoted string which is not part of a '#define' macro definition. 76*7981Srrh Macros are not expanded while processing a '#define' or '#undef'. 77*7981Srrh Thus 78*7981Srrh #define foo bletch 79*7981Srrh #define bar foo 80*7981Srrh #undef foo 81*7981Srrh bar 82*7981Srrh produces "foo". The token appearing immediately after a 83*7981Srrh '#ifdef' or '#ifndef' is not expanded (of course!). 84*7981Srrh Macros are not expanded during the scan which determines the actual 85*7981Srrh parameters to another macro call. Thus 86*7981Srrh #define foo(a,b)b a 87*7981Srrh #define bar hi 88*7981Srrh foo(bar, 89*7981Srrh #define bar bye 90*7981Srrh ) 91*7981Srrh produces " bye" (and warns about the redefinition of 'bar'). 92*7981Srrh 93*7981SrrhThere are some differences between the new and the old preprocessor. 94*7981SrrhBugs fixed: 95*7981Srrh "1.e4" is recognized as a floating-point number, rather than as an 96*7981Srrh opportunity to expand the possible macro name "e4". 97*7981Srrh Any kind and amount of white space (space, tab, linefeed, vertical tab, 98*7981Srrh formfeed, carriage return) is allowed between a macro name and 99*7981Srrh the left parenthesis which introduces its actual parameters. 100*7981Srrh The comma operator is legal in preprocessor '#if' statements. 101*7981Srrh Macros with parameters are legal in preprocessor '#if' statements. 102*7981Srrh Single-character character constants are legal in preprocessor '#if' statements. 103*7981Srrh Linefeeds are put out in the proper place when a multiline comment 104*7981Srrh is not passed through to the output. 105*7981Srrh The following example expands to "# # #" : 106*7981Srrh #define foo # 107*7981Srrh foo foo foo 108*7981Srrh If the -R flag is not specified then the invocation of some recursive 109*7981Srrh macros is trapped and the recursion forcibly terminated with an 110*7981Srrh error message. The recursions that are trapped are the ones 111*7981Srrh in which the nesting level is non-decreasing from some point on. 112*7981Srrh In particular, 113*7981Srrh #define a a 114*7981Srrh a 115*7981Srrh will be detected. (Use "#undef a" if that is what you want.) 116*7981Srrh The recursion 117*7981Srrh #define a c b 118*7981Srrh #define b c a 119*7981Srrh #define c foo 120*7981Srrh a 121*7981Srrh will not be detected because the nesting level decreases after 122*7981Srrh each expansion of "c". 123*7981Srrh The -R flag specifically allows recursive macros and recursion will 124*7981Srrh be strictly obeyed (to the extent that space is available). 125*7981Srrh Assuming that -R is specified: 126*7981Srrh #define a a 127*7981Srrh a 128*7981Srrh causes an infinite loop with very little output. The tail recursion 129*7981Srrh #define a <b 130*7981Srrh #define b >a 131*7981Srrh a 132*7981Srrh causes the string "<>" to be output infinitely many times. The 133*7981Srrh non-tail recursion 134*7981Srrh #define a b> 135*7981Srrh #define b a< 136*7981Srrh a 137*7981Srrh complains "too much pushback", dumps the pushback, and continues 138*7981Srrh (again, infinitely). 139*7981Srrh 140*7981SrrhStylistic choice: 141*7981Srrh Nothing (not even linefeeds) is output while a false '#if', '#ifdef', 142*7981Srrh or '#ifndef' is in effect. Thus when all conditions become true 143*7981Srrh a line of the form "# 12345 \"foo.c\"" is output (unless -P). 144*7981Srrh Error and warning messages always appear on standard error (file 145*7981Srrh descriptor 2). 146*7981Srrh Mismatch between the number of formals and actuals in a macro call 147*7981Srrh produces only a warning, and not an error. Excess actuals 148*7981Srrh are ignored; missing actuals are turned into null strings. 149*7981Srrh 150*7981SrrhIncompatibility: 151*7981Srrh The virgule '/' in "a=/*b" is interpreted as the first character of 152*7981Srrh the pair "/*" which introduces a comment, rather than as the 153*7981Srrh second character of the divide-and-replace operator "=/". 154*7981Srrh This incompatibility reflects the recent change in the C language 155*7981Srrh which made "a/=*b" the legal way to write such a statement 156*7981Srrh if the meaning "a=a/ *b" is intended. 157