17981Srrh# 2*7983Srrh# @(#)README 1.2 08/30/82 37981Srrh# 4*7983SrrhAugust 30, 1982 5*7983SrrhFixed by Kurt Shoens, UCB 6*7983SrrhIf the "#line n name" occurs, then all future references 7*7983Srrhto the current file are generated in terms of "name", instead 8*7983Srrhof the name of file given to cpp in its command argument 9*7983Srrh 107981SrrhAugust 25, 1978 117981Srrh 127981SrrhFiles in this directory form the C preprocessor, which handles '#include' 137981Srrhfiles and macro definition and expansion for the C compiler. 147981SrrhThis new version was written by John F. Reiser and is from 5 to 12 157981Srrhtimes faster (on UNIX systems) than the old. 167981Srrh 177981SrrhTo create the executable file 'cpp' in the current directory: 187981Srrh make 197981Srrh 207981SrrhTo install the preprocessor 'cpp' so it will be used by the C compiler: 217981Srrh : safety first: backup the existing version 227981Srrh cp /lib/cpp /lib/ocpp 237981Srrh : install the new version 247981Srrh cp cpp /lib/cpp 257981Srrh 267981SrrhInvocation 277981Srrh cpp [-CEPR] [-Dname] ... [-Dname=def] ... [-Idirectory] ... 287981Srrh [-Uname] ... [<infile>] [<outfile>] 297981Srrh 307981Srrh If there are two non-flag arguments then the first is the name of the 317981Srrh input file and the second is the name of the output file. If there is 327981Srrh one non-flag argument then it is the name of the input file and the 337981Srrh output is written on the standard output. If there are no non-flag 347981Srrh arguments then the input is taken from the standard input and the output 357981Srrh is written on the standard output. Flag arguments are: 367981Srrh 377981Srrh -C retain comments in output 387981Srrh -Dname define name as "1" 397981Srrh -Dname=def define name as def 407981Srrh -E ignored 417981Srrh -Idirectory add directory to search list for #include files 427981Srrh -P don't insert lines "# 12 \"foo.c\"" into output 437981Srrh -R allow recursive macros 447981Srrh -Uname undefine name 457981Srrh 467981SrrhDocumentation clarifications: 477981Srrh Symbols defined on the command line by "-Dfoo" are defined as "1", 487981Srrh i.e., as if they had been defined by "#define foo 1" or "-Dfoo=1". 497981Srrh The directory search order for #include files is 507981Srrh 1) the directory of the file which contains the #include request 517981Srrh (e.g. #include is relative to the file being scanned when 527981Srrh the request is made) 537981Srrh 2) the directories specified by -I, in left-to-right order 547981Srrh 3) the standard directory(s) (which for UNIX is /usr/include) 557981Srrh An unescaped linefeed (the single character "\n") terminates a 567981Srrh character constant or quoted string. 577981Srrh An escaped linefeed (the two-character sequence "\\\n") may be 587981Srrh used in the body of a '#define' statement to continue 597981Srrh the definition onto the next line. The escaped linefeed is 607981Srrh not included in the macro body. 617981Srrh Comments are uniformly removed (except if the argument -C is specified). 627981Srrh They are also ignored, except that a comment terminates a token. 637981Srrh Thus "foo/* la di da */bar" may expand 'foo' and 'bar' but 647981Srrh will never expand 'foobar'. If neither 'foo' nor 'bar' is a 657981Srrh macro then the output is "foobar", even if 'foobar' 667981Srrh is defined as something else. The file 677981Srrh #define foo(a,b)b/**/a 687981Srrh foo(1,2) 697981Srrh produces "21" because the comment causes a break which enables 707981Srrh the recognition of 'b' and 'a' as formals in the string "b/**/a". 717981Srrh Macro formal parameters are recognized in '#define' bodies even inside 727981Srrh character constants and quoted strings. The output from 737981Srrh #define foo(a) '\a' 747981Srrh foo(bar) 757981Srrh is the seven characters " '\\bar'". Macro names are not recognized 767981Srrh inside character constants or quoted strings during the regular scan. 777981Srrh Thus 787981Srrh #define foo bar 797981Srrh printf("foo"); 807981Srrh does not expand 'foo' in the second line, because it is inside 817981Srrh a quoted string which is not part of a '#define' macro definition. 827981Srrh Macros are not expanded while processing a '#define' or '#undef'. 837981Srrh Thus 847981Srrh #define foo bletch 857981Srrh #define bar foo 867981Srrh #undef foo 877981Srrh bar 887981Srrh produces "foo". The token appearing immediately after a 897981Srrh '#ifdef' or '#ifndef' is not expanded (of course!). 907981Srrh Macros are not expanded during the scan which determines the actual 917981Srrh parameters to another macro call. Thus 927981Srrh #define foo(a,b)b a 937981Srrh #define bar hi 947981Srrh foo(bar, 957981Srrh #define bar bye 967981Srrh ) 977981Srrh produces " bye" (and warns about the redefinition of 'bar'). 987981Srrh 997981SrrhThere are some differences between the new and the old preprocessor. 1007981SrrhBugs fixed: 1017981Srrh "1.e4" is recognized as a floating-point number, rather than as an 1027981Srrh opportunity to expand the possible macro name "e4". 1037981Srrh Any kind and amount of white space (space, tab, linefeed, vertical tab, 1047981Srrh formfeed, carriage return) is allowed between a macro name and 1057981Srrh the left parenthesis which introduces its actual parameters. 1067981Srrh The comma operator is legal in preprocessor '#if' statements. 1077981Srrh Macros with parameters are legal in preprocessor '#if' statements. 1087981Srrh Single-character character constants are legal in preprocessor '#if' statements. 1097981Srrh Linefeeds are put out in the proper place when a multiline comment 1107981Srrh is not passed through to the output. 1117981Srrh The following example expands to "# # #" : 1127981Srrh #define foo # 1137981Srrh foo foo foo 1147981Srrh If the -R flag is not specified then the invocation of some recursive 1157981Srrh macros is trapped and the recursion forcibly terminated with an 1167981Srrh error message. The recursions that are trapped are the ones 1177981Srrh in which the nesting level is non-decreasing from some point on. 1187981Srrh In particular, 1197981Srrh #define a a 1207981Srrh a 1217981Srrh will be detected. (Use "#undef a" if that is what you want.) 1227981Srrh The recursion 1237981Srrh #define a c b 1247981Srrh #define b c a 1257981Srrh #define c foo 1267981Srrh a 1277981Srrh will not be detected because the nesting level decreases after 1287981Srrh each expansion of "c". 1297981Srrh The -R flag specifically allows recursive macros and recursion will 1307981Srrh be strictly obeyed (to the extent that space is available). 1317981Srrh Assuming that -R is specified: 1327981Srrh #define a a 1337981Srrh a 1347981Srrh causes an infinite loop with very little output. The tail recursion 1357981Srrh #define a <b 1367981Srrh #define b >a 1377981Srrh a 1387981Srrh causes the string "<>" to be output infinitely many times. The 1397981Srrh non-tail recursion 1407981Srrh #define a b> 1417981Srrh #define b a< 1427981Srrh a 1437981Srrh complains "too much pushback", dumps the pushback, and continues 1447981Srrh (again, infinitely). 1457981Srrh 1467981SrrhStylistic choice: 1477981Srrh Nothing (not even linefeeds) is output while a false '#if', '#ifdef', 1487981Srrh or '#ifndef' is in effect. Thus when all conditions become true 1497981Srrh a line of the form "# 12345 \"foo.c\"" is output (unless -P). 1507981Srrh Error and warning messages always appear on standard error (file 1517981Srrh descriptor 2). 1527981Srrh Mismatch between the number of formals and actuals in a macro call 1537981Srrh produces only a warning, and not an error. Excess actuals 1547981Srrh are ignored; missing actuals are turned into null strings. 1557981Srrh 1567981SrrhIncompatibility: 1577981Srrh The virgule '/' in "a=/*b" is interpreted as the first character of 1587981Srrh the pair "/*" which introduces a comment, rather than as the 1597981Srrh second character of the divide-and-replace operator "=/". 1607981Srrh This incompatibility reflects the recent change in the C language 1617981Srrh which made "a/=*b" the legal way to write such a statement 1627981Srrh if the meaning "a=a/ *b" is intended. 163