home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / gccdist / gcc / cpp.info-2 < prev    next >
Encoding:
Text File  |  1992-09-10  |  32.7 KB  |  882 lines

  1. Info file cpp.info, produced by Makeinfo, -*- Text -*- from input
  2. file cpp.texinfo.
  3.  
  4. This file documents the GNU C Preprocessor.
  5.  
  6. Copyright (C) 1987, 1989 Free Software Foundation, Inc.
  7.  
  8. Permission is granted to make and distribute verbatim copies of this
  9. manual provided the copyright notice and this permission notice are
  10. preserved on all copies.
  11.  
  12. Permission is granted to copy and distribute modified versions of
  13. this manual under the conditions for verbatim copying, provided also
  14. that the entire resulting derived work is distributed under the terms
  15. of a permission notice identical to this one.
  16.  
  17. Permission is granted to copy and distribute translations of this
  18. manual into another language, under the above conditions for modified
  19. versions.
  20.  
  21.  
  22. 
  23. File: cpp.info,  Node: Self-Reference,  Next: Argument Prescan,  Prev: Side Effects,  Up: Macro Pitfalls
  24.  
  25. Self-Referential Macros
  26. .......................
  27.  
  28.  A "self-referential" macro is one whose name appears in its definition.
  29. A special feature of ANSI Standard C is that the self-reference is
  30. not considered a macro call.  It is passed into the preprocessor
  31. output unchanged.
  32.  
  33. Let's consider an example:
  34.  
  35.      #define foo (4 + foo)
  36.  
  37. where `foo' is also a variable in your program.
  38.  
  39. Following the ordinary rules, each reference to `foo' will expand
  40. into `(4 + foo)'; then this will be rescanned and will expand into
  41. `(4 + (4 + foo))'; and so on until it causes a fatal error (memory
  42. full) in the preprocessor.
  43.  
  44. However, the special rule about self-reference cuts this process
  45. short after one step, at `(4 + foo)'.  Therefore, this macro
  46. definition has the possibly useful effect of causing the program to
  47. add 4 to the value of `foo' wherever `foo' is referred to.
  48.  
  49. In most cases, it is a bad idea to take advantage of this feature.  A
  50. person reading the program who sees that `foo' is a variable will not
  51. expect that it is a macro as well.  The reader will come across the
  52. identifier `foo' in the program and think its value should be that of
  53. the variable `foo', whereas in fact the value is four greater.
  54.  
  55. The special rule for self-reference applies also to "indirect"
  56. self-reference.  This is the case where a macro X expands to use a
  57. macro `y', and `y''s expansion refers to the macro `x'.  The
  58. resulting reference to `x' comes indirectly from the expansion of
  59. `x', so it is a self-reference and is not further expanded.  Thus,
  60. after
  61.  
  62.      #define x (4 + y)
  63.      #define y (2 * x)
  64.  
  65. `x' would expand into `(4 + (2 * x))'.  Clear?
  66.  
  67. But suppose `y' is used elsewhere, not from the definition of `x'. 
  68. Then the use of `x' in the expansion of `y' is not a self-reference
  69. because `x' is not "in progress".  So it does expand.  However, the
  70. expansion of `x' contains a reference to `y', and that is an indirect
  71. self-reference now because `y' is "in progress".  The result is that
  72. `y' expands to `(2 * (4 + y))'.
  73.  
  74. It is not clear that this behavior would ever be useful, but it is
  75. specified by the ANSI C standard, so you need to understand it.
  76.  
  77.  
  78. 
  79. File: cpp.info,  Node: Argument Prescan,  Next: Cascaded Macros,  Prev: Self-Reference,  Up: Macro Pitfalls
  80.  
  81. Separate Expansion of Macro Arguments
  82. .....................................
  83.  
  84.  We have explained that the expansion of a macro, including the
  85. substituted actual arguments, is scanned over again for macro calls
  86. to be expanded.
  87.  
  88. What really happens is more subtle: first each actual argument text
  89. is scanned separately for macro calls.  Then the results of this are
  90. substituted into the macro body to produce the macro expansion, and
  91. the macro expansion is scanned again for macros to expand.
  92.  
  93. The result is that the actual arguments are scanned *twice* to expand
  94. macro calls in them.
  95.  
  96. Most of the time, this has no effect.  If the actual argument
  97. contained any macro calls, they are expanded during the first scan. 
  98. The result therefore contains no macro calls, so the second scan does
  99. not change it.  If the actual argument were substituted as given,
  100. with no prescan, the single remaining scan would find the same macro
  101. calls and produce the same results.
  102.  
  103. You might expect the double scan to change the results when a
  104. self-referential macro is used in an actual argument of another macro
  105. (*note Self-Reference::.): the self-referential macro would be
  106. expanded once in the first scan, and a second time in the second
  107. scan.  But this is not what happens.  The self-references that do not
  108. expand in the first scan are marked so that they will not expand in
  109. the second scan either.
  110.  
  111. The prescan is not done when an argument is stringified or
  112. concatenated.  Thus,
  113.  
  114.      #define str(s) #s
  115.      #define foo 4
  116.      str (foo)
  117.  
  118. expands to `"foo"'.  Once more, prescan has been prevented from
  119. having any noticeable effect.
  120.  
  121. More precisely, stringification and concatenation use the argument as
  122. written, in un-prescanned form.  The same actual argument would be
  123. used in prescanned form if it is substituted elsewhere without
  124. stringification or concatenation.
  125.  
  126.      #define str(s) #s lose(s)
  127.      #define foo 4
  128.      str (foo)
  129.  
  130. expands to `"foo" lose(4)'.
  131.  
  132. You might now ask, "Why mention the prescan, if it makes no difference?
  133. And why not skip it and make the preprocessor faster?"  The answer is
  134. that the prescan does make a difference in three special cases:
  135.  
  136.    * Nested calls to a macro.
  137.  
  138.    * Macros that call other macros that stringify or concatenate.
  139.  
  140.    * Macros whose expansions contain unshielded commas.
  141.  
  142. We say that "nested" calls to a macro occur when a macro's actual
  143. argument contains a call to that very macro.  For example, if `f' is
  144. a macro that expects one argument, `f (f (1))' is a nested pair of
  145. calls to `f'.  The desired expansion is made by expanding `f (1)' and
  146. substituting that into the definition of `f'.  The prescan causes the
  147. expected result to happen.  Without the prescan, `f (1)' itself would
  148. be substituted as an actual argument, and the inner use of `f' would
  149. appear during the main scan as an indirect self-reference and would
  150. not be expanded.  Here, the prescan cancels an undesirable side
  151. effect (in the medical, not computational, sense of the term) of the
  152. special rule for self-referential macros.
  153.  
  154. But prescan causes trouble in certain other cases of nested macro
  155. calls.  Here is an example:
  156.  
  157.      #define foo  a,b
  158.      #define bar(x) lose(x)
  159.      #define lose(x) (1 + (x))
  160.      
  161.      bar(foo)
  162.  
  163. We would like `bar(foo)' to turn into `(1 + (foo))', which would then
  164. turn into `(1 + (a,b))'.  But instead, `bar(foo)' expands into
  165. `lose(a,b)', and you get an error because `lose' requires a single
  166. argument.  In this case, the problem is easily solved by the same
  167. parentheses that ought to be used to prevent misnesting of arithmetic
  168. operations:
  169.  
  170.      #define foo (a,b)
  171.      #define bar(x) lose((x))
  172.  
  173. The problem is more serious when the operands of the macro are not
  174. expressions; for example, when they are statements.  Then parentheses
  175. are unacceptable because they would make for invalid C code:
  176.  
  177.      #define foo { int a, b; ... }
  178.  
  179. In GNU C you can shield the commas using the `({...})' construct
  180. which turns a compound statement into an expression:
  181.  
  182.      #define foo ({ int a, b; ... })
  183.  
  184. Or you can rewrite the macro definition to avoid such commas:
  185.  
  186.      #define foo { int a; int b; ... }
  187.  
  188. There is also one case where prescan is useful.  It is possible to
  189. use prescan to expand an argument and then stringify it--if you use
  190. two levels of macros.  Let's add a new macro `xstr' to the example
  191. shown above:
  192.  
  193.      #define xstr(s) str(s)
  194.      #define str(s) #s
  195.      #define foo 4
  196.      xstr (foo)
  197.  
  198. This expands into `"4"', not `"foo"'.  The reason for the difference
  199. is that the argument of `xstr' is expanded at prescan (because `xstr'
  200. does not specify stringification or concatenation of the argument). 
  201. The result of prescan then forms the actual argument for `str'. 
  202. `str' uses its argument without prescan because it performs
  203. stringification; but it cannot prevent or undo the prescanning
  204. already done by `xstr'.
  205.  
  206.  
  207. 
  208. File: cpp.info,  Node: Cascaded Macros,  Prev: Argument Prescan,  Up: Macro Pitfalls
  209.  
  210. Cascaded Use of Macros
  211. ......................
  212.  
  213.  A "cascade" of macros is when one macro's body contains a reference
  214. to another macro.  This is very common practice.  For example,
  215.  
  216.      #define BUFSIZE 1020
  217.      #define TABLESIZE BUFSIZE
  218.  
  219. This is not at all the same as defining `TABLESIZE' to be `1020'. 
  220. The `#define' for `TABLESIZE' uses exactly the body you specify--in
  221. this case, `BUFSIZE'--and does not check to see whether it too is the
  222. name of a macro.
  223.  
  224. It's only when you *use* `TABLESIZE' that the result of its expansion
  225. is checked for more macro names.
  226.  
  227. This makes a difference if you change the definition of `BUFSIZE' at
  228. some point in the source file.  `TABLESIZE', defined as shown, will
  229. always expand using the definition of `BUFSIZE' that is currently in
  230. effect:
  231.  
  232.      #define BUFSIZE 1020
  233.      #define TABLESIZE BUFSIZE
  234.      #undef BUFSIZE
  235.      #define BUFSIZE 37
  236.  
  237. Now `TABLESIZE' expands (in two stages) to `37'.
  238.  
  239.  
  240. 
  241. File: cpp.info,  Node: Conditionals,  Next: Combining Sources,  Prev: Macros,  Up: Top
  242.  
  243. Conditionals
  244. ============
  245.  
  246. In a macro processor, a "conditional" is a command that allows a part
  247. of the program to be ignored during compilation, on some conditions. 
  248. In the C preprocessor, a conditional can test either an arithmetic
  249. expression or whether a name is defined as a macro.
  250.  
  251. A conditional in the C preprocessor resembles in some ways an `if'
  252. statement in C, but it is important to understand the difference
  253. between them.  The condition in an `if' statement is tested during
  254. the execution of your program.  Its purpose is to allow your program
  255. to behave differently from run to run, depending on the data it is
  256. operating on.  The condition in a preprocessor conditional command is
  257. tested when your program is compiled.  Its purpose is to allow
  258. different code to be included in the program depending on the
  259. situation at the time of compilation.
  260.  
  261. * Menu:
  262.  
  263. * Uses: Conditional Uses.       What conditionals are for.
  264. * Syntax: Conditional Syntax.   How conditionals are written.
  265. * Deletion: Deleted Code.       Making code into a comment.
  266. * Macros: Conditionals-Macros.  Why conditionals are used with macros.
  267. * Errors: #error Command.       Detecting inconsistent compilation parameters.
  268.  
  269.  
  270. 
  271. File: cpp.info,  Node: Conditional Uses,  Next: Conditional Syntax,  Prev: Conditionals,  Up: Conditionals
  272.  
  273. Why Conditionals are Used
  274. -------------------------
  275.  
  276. Generally there are three kinds of reason to use a conditional.
  277.  
  278.    * A program may need to use different code depending on the
  279.      machine or operating system it is to run on.  In some cases the
  280.      code for one operating system may be erroneous on another
  281.      operating system; for example, it might refer to library
  282.      routines that do not exist on the other system.  When this
  283.      happens, it is not enough to avoid executing the invalid code:
  284.      merely having it in the program makes it impossible to link the
  285.      program and run it.  With a preprocessor conditional, the
  286.      offending code can be effectively excised from the program when
  287.      it is not valid.
  288.  
  289.    * You may want to be able to compile the same source file into two
  290.      different programs.  Sometimes the difference between the
  291.      programs is that one makes frequent time-consuming consistency
  292.      checks on its intermediate data while the other does not.
  293.  
  294.    * A conditional whose condition is always false is a good way to
  295.      exclude code from the program but keep it as a sort of comment
  296.      for future reference.
  297.  
  298. Most simple programs that are intended to run on only one machine
  299. will not need to use preprocessor conditionals.
  300.  
  301.  
  302. 
  303. File: cpp.info,  Node: Conditional Syntax,  Next: Deleted Code,  Prev: Conditional Uses,  Up: Conditionals
  304.  
  305. Syntax of Conditionals
  306. ----------------------
  307.  
  308. A conditional in the C preprocessor begins with a "conditional
  309. command": `#if', `#ifdef' or `#ifndef'.  *Note Conditionals-Macros::,
  310. for info on `#ifdef' and `#ifndef'; only `#if' is explained here.
  311.  
  312. * Menu:
  313.  
  314. * If: #if Command.     Basic conditionals using `#if' and `#endif'.
  315. * Else: #else Command. Including some text if the condition fails.
  316. * Elif: #elif Command. Testing several alternative possibilities.
  317.  
  318.  
  319. 
  320. File: cpp.info,  Node: #if Command,  Next: #else Command,  Prev: Conditional Syntax,  Up: Conditional Syntax
  321.  
  322. The `#if' Command
  323. .................
  324.  
  325.  The `#if' command in its simplest form consists of
  326.  
  327.      #if EXPRESSION
  328.      CONTROLLED TEXT
  329.      #endif /* EXPRESSION */
  330.  
  331. The comment following the `#endif' is not required, but it is a good
  332. practice because it helps people match the `#endif' to the
  333. corresponding `#if'.  Such comments should always be used, except in
  334. short conditionals that are not nested.  In fact, you can put
  335. anything at all after the `#endif' and it will be ignored by the GNU
  336. C preprocessor, but only comments are acceptable in ANSI Standard C.
  337.  
  338. EXPRESSION is a C expression of integer type, subject to stringent
  339. restrictions.  It may contain
  340.  
  341.    * Integer constants, which are all regarded as `long' or `unsigned
  342.      long'.
  343.  
  344.    * Character constants, which are interpreted according to the
  345.      character set and conventions of the machine and operating
  346.      system on which the preprocessor is running.  The GNU C
  347.      preprocessor uses the C data type `char' for these character
  348.      constants; therefore, whether some character codes are negative
  349.      is determined by the C compiler used to compile the
  350.      preprocessor.  If it treats `char' as signed, then character
  351.      codes large enough to set the sign bit will be considered
  352.      negative; otherwise, no character code is considered negative.
  353.  
  354.    * Arithmetic operators for addition, subtraction, multiplication,
  355.      division, bitwise operations, shifts, comparisons, and `&&' and
  356.      `||'.
  357.  
  358.    * Identifiers that are not macros, which are all treated as zero(!).
  359.  
  360.    * Macro calls.  All macro calls in the expression are expanded
  361.      before actual computation of the expression's value begins.
  362.  
  363. Note that `sizeof' operators and `enum'-type values are not allowed. 
  364. `enum'-type values, like all other identifiers that are not taken as
  365. macro calls and expanded, are treated as zero.
  366.  
  367. The text inside of a conditional can include preprocessor commands. 
  368. Then the commands inside the conditional are obeyed only if that
  369. branch of the conditional succeeds.  The text can also contain other
  370. conditional groups.  However, the `#if''s and `#endif''s must balance.
  371.  
  372.  
  373. 
  374. File: cpp.info,  Node: #else Command,  Next: #elif Command,  Prev: #if Command,  Up: Conditional Syntax
  375.  
  376. The `#else' Command
  377. ...................
  378.  
  379.  The `#else' command can be added to a conditional to provide
  380. alternative text to be used if the condition is false.  This looks like
  381.  
  382.      #if EXPRESSION
  383.      TEXT-IF-TRUE
  384.      #else /* Not EXPRESSION */
  385.      TEXT-IF-FALSE
  386.      #endif /* Not EXPRESSION */
  387.  
  388. If EXPRESSION is nonzero, and the TEXT-IF-TRUE is considered
  389. included, then `#else' acts like a failing conditional and the
  390. TEXT-IF-FALSE is ignored.  Contrariwise, if the `#if' conditional
  391. fails, the TEXT-IF-FALSE is considered included.
  392.  
  393.  
  394. 
  395. File: cpp.info,  Node: #elif Command,  Prev: #else Command,  Up: Conditional Syntax
  396.  
  397. The `#elif' Command
  398. ...................
  399.  
  400.  One common case of nested conditionals is used to check for more than
  401. two possible alternatives.  For example, you might have
  402.  
  403.      #if X == 1
  404.      ...
  405.      #else /* X != 1 */
  406.      #if X == 2
  407.      ...
  408.      #else /* X != 2 */
  409.      ...
  410.      #endif /* X != 2 */
  411.      #endif /* X != 1 */
  412.  
  413. Another conditional command, `#elif', allows this to be abbreviated
  414. as follows:
  415.  
  416.      #if X == 1
  417.      ...
  418.      #elif X == 2
  419.      ...
  420.      #else /* X != 2 and X != 1*/
  421.      ...
  422.      #endif /* X != 2 and X != 1*/
  423.  
  424. `#elif' stands for "else if".  Like `#else', it goes in the middle of
  425. a `#if'-`#endif' pair and subdivides it; it does not require a
  426. matching `#endif' of its own.  Like `#if', the `#elif' command
  427. includes an expression to be tested.
  428.  
  429. The text following the `#elif' is processed only if the original
  430. `#if'-condition failed and the `#elif' condition succeeeds.  More
  431. than one `#elif' can go in the same `#if'-`#endif' group.  Then the
  432. text after each `#elif' is processed only if the `#elif' condition
  433. succeeds after the original `#if' and any previous `#elif''s within
  434. it have failed.  `#else' is equivalent to `#elif 1', and `#else' is
  435. allowed after any number of `#elif''s, but `#elif' may not follow a
  436. `#else'.
  437.  
  438.  
  439. 
  440. File: cpp.info,  Node: Deleted Code,  Next: Conditionals-Macros,  Prev: Conditional Syntax,  Up: Conditionals
  441.  
  442. Keeping Deleted Code for Future Reference
  443. -----------------------------------------
  444.  
  445. If you replace or delete a part of the program but want to keep the
  446. old code around as a comment for future reference, the easy way to do
  447. this is to put `#if 0' before it and `#endif' after it.
  448.  
  449. This works even if the code being turned off contains conditionals,
  450. but they must be entire conditionals (balanced `#if' and `#endif').
  451.  
  452.  
  453. 
  454. File: cpp.info,  Node: Conditionals-Macros,  Next: #error Command,  Prev: Deleted Code,  Up: Conditionals
  455.  
  456. Conditionals and Macros
  457. -----------------------
  458.  
  459. Conditionals are rarely useful except in connection with macros.  A
  460. `#if' command whose expression uses no macros is equivalent to `#if
  461. 1' or `#if 0'; you might as well determine which one, by computing
  462. the value of the expression yourself, and then simplify the program. 
  463. But when the expression uses macros, its value can vary from
  464. compilation to compilation.
  465.  
  466. For example, here is a conditional that tests the expression `BUFSIZE
  467. == 1020', where `BUFSIZE' must be a macro.
  468.  
  469.      #if BUFSIZE == 1020
  470.        printf ("Large buffers!\n");
  471.      #endif /* BUFSIZE is large */
  472.  
  473. The special operator `defined' may be used in `#if' expressions to
  474. test whether a certain name is defined as a macro.  Either `defined
  475. NAME' or `defined (NAME)' is an expression whose value is 1 if NAME
  476. is defined as macro at the current point in the program, and 0
  477. otherwise.  For the `defined' operator it makes no difference what
  478. the definition of the macro is; all that matters is whether there is
  479. a definition.  Thus, for example,
  480.  
  481.      #if defined (vax) || defined (ns16000)
  482.  
  483. would include the following code if either of the names `vax' and
  484. `ns16000' is defined as a macro.
  485.  
  486. If a macro is defined and later undefined with `#undef', subsequent
  487. use of the `defined' operator will return 0, because the name is no
  488. longer defined.  If the macro is defined again with another
  489. `#define', `defined' will recommence returning 1.
  490.  
  491. Conditionals that test just the definedness of one name are very
  492. common, so there are two special short conditional commands for this
  493. case.  They are
  494.  
  495. `#ifdef NAME'
  496.      is equivalent to `#if defined (NAME)'.
  497.  
  498. `#ifndef NAME'
  499.      is equivalent to `#if ! defined (NAME)'.
  500.  
  501. Macro definitions can vary between compilations for several reasons.
  502.  
  503.    * Some macros are predefined on each kind of machine.  For
  504.      example, on a Vax, the name `vax' is a predefined macro.  On
  505.      other machines, it would not be defined.
  506.  
  507.    * Many more macros are defined by system header files.  Different
  508.      systems and machines define different macros, or give them
  509.      different values.  It is useful to test these macros with
  510.      conditionals to avoid using a system feature on a machine where
  511.      it is not implemented.
  512.  
  513.    * Macros are a common way of allowing users to customize a program
  514.      for different machines or applications.  For example, the macro
  515.      `BUFSIZE' might be defined in a configuration file for your
  516.      program that is included as a header file in each source file. 
  517.      You would use `BUFSIZE' in a preprocessor conditional in order
  518.      to generate different code depending on the chosen configuration.
  519.  
  520.    * Macros can be defined or undefined with `-D' and `-U' command
  521.      options when you compile the program.  You can arrange to
  522.      compile the same source file into two different programs by
  523.      choosing a macro name to specify which program you want, writing
  524.      conditionals to test whether or how this macro is defined, and
  525.      then controlling the state of the macro with compiler command
  526.      options.  *Note Invocation::.
  527.  
  528.  
  529. 
  530. File: cpp.info,  Node: #error Command,  Prev: Conditionals-Macros,  Up: Conditionals
  531.  
  532. The `#error' Command
  533. --------------------
  534.  
  535. The command `#error' causes the preprocessor to report a fatal error.
  536. The rest of the line that follows `#error' is used as the error
  537. message.
  538.  
  539. You would use `#error' inside of a conditional that detects a
  540. combination of parameters which you know the program does not
  541. properly support.  For example, if you know that the program will not
  542. run properly on a Vax, you might write
  543.  
  544.      #ifdef vax
  545.      #error Won't work on Vaxen.  See comments at get_last_object.
  546.      #endif
  547.  
  548. *Note Nonstandard Predefined::, for why this works.
  549.  
  550. If you have several configuration parameters that must be set up by
  551. the installation in a consistent way, you can use conditionals to
  552. detect an inconsistency and report it with `#error'.  For example,
  553.  
  554.      #if HASH_TABLE_SIZE % 2 == 0 || HASH_TABLE_SIZE % 3 == 0 \
  555.          || HASH_TABLE_SIZE % 5 == 0
  556.      #error HASH_TABLE_SIZE should not be divisible by a small prime
  557.      #endif
  558.  
  559.  
  560. 
  561. File: cpp.info,  Node: Combining Sources,  Next: Other Commands,  Prev: Conditionals,  Up: Top
  562.  
  563. Combining Source Files
  564. ======================
  565.  
  566. One of the jobs of the C preprocessor is to inform the C compiler of
  567. where each line of C code came from: which source file and which line
  568. number.
  569.  
  570. C code can come from multiple source files if you use `#include';
  571. both `#include' and the use of conditionals and macros can cause the
  572. line number of a line in the preprocessor output to be different from
  573. the line's number in the original source file.  You will appreciate
  574. the value of making both the C compiler (in error messages) and
  575. symbolic debuggers such as GDB use the line numbers in your source
  576. file.
  577.  
  578. The C preprocessor builds on this feature by offering a command by
  579. which you can control the feature explicitly.  This is useful when a
  580. file for input to the C preprocessor is the output from another
  581. program such as the `bison' parser generator, which operates on
  582. another file that is the true source file.  Parts of the output from
  583. `bison' are generated from scratch, other parts come from a standard
  584. parser file.  The rest are copied nearly verbatim from the source
  585. file, but their line numbers in the `bison' output are not the same
  586. as their original line numbers.  Naturally you would like compiler
  587. error messages and symbolic debuggers to know the original source
  588. file and line number of each line in the `bison' output.
  589.  
  590. `bison' arranges this by writing `#line' commands into the output
  591. file.  `#line' is a command that specifies the original line number
  592. and source file name for subsequent input in the current preprocessor
  593. input file.  `#line' has three variants:
  594.  
  595. `#line LINENUM'
  596.      Here LINENUM is a decimal integer constant.  This specifies that
  597.      the line number of the following line of input, in its original
  598.      source file, was LINENUM.
  599.  
  600. `#line LINENUM FILENAME'
  601.      Here LINENUM is a decimal integer constant and FILENAME is a
  602.      string constant.  This specifies that the following line of
  603.      input came originally from source file FILENAME and its line
  604.      number there was LINENUM.  Keep in mind that FILENAME is not
  605.      just a file name; it is surrounded by doublequote characters so
  606.      that it looks like a string constant.
  607.  
  608. `#line ANYTHING ELSE'
  609.      ANYTHING ELSE is checked for macro calls, which are expanded. 
  610.      The result should be a decimal integer constant followed
  611.      optionally by a string constant, as described above.
  612.  
  613. `#line' commands alter the results of the `__FILE__' and `__LINE__'
  614. predefined macros from that point on.  *Note Standard Predefined::.
  615.  
  616.  
  617. 
  618. File: cpp.info,  Node: Other Commands,  Next: Output,  Prev: Combining Sources,  Up: Top
  619.  
  620. Miscellaneous Preprocessor Commands
  621. ===================================
  622.  
  623. This section describes three additional preprocessor commands.  They
  624. are not very useful, but are mentioned for completeness.
  625.  
  626. The "null command" consists of a `#' followed by a Newline, with only
  627. whitespace (including comments) in between.  A null command is
  628. understood as a preprocessor command but has no effect on the
  629. preprocessor output.  The primary significance of the existence of
  630. the null command is that an input line consisting of just a `#' will
  631. produce no output, rather than a line of output containing just a
  632. `#'.  Supposedly some old C programs contain such lines.
  633.  
  634. The `#pragma' command is specified in the ANSI standard to have an
  635. arbitrary implementation-defined effect.  In the GNU C preprocessor,
  636. `#pragma' commands are ignored, except for `#pragma once' (*note
  637. Once-Only::.).
  638.  
  639. The `#ident' command is supported for compatibility with certain
  640. other systems.  It is followed by a line of text.  On certain
  641. systems, the text is copied into a special place in the object file;
  642. on most systems, the text is ignored and this directive has no effect.
  643.  
  644.  
  645. 
  646. File: cpp.info,  Node: Output,  Next: Invocation,  Prev: Other Commands,  Up: Top
  647.  
  648. C Preprocessor Output
  649. =====================
  650.  
  651. The output from the C preprocessor looks much like the input, except
  652. that all preprocessor command lines have been replaced with blank
  653. lines and all comments with spaces.  Whitespace within a line is not
  654. altered; however, a space is inserted after the expansions of most
  655. macro calls.
  656.  
  657. Source file name and line number information is conveyed by lines of
  658. the form
  659.  
  660.      # LINENUM FILENAME FLAG
  661.  
  662. which are inserted as needed into the middle of the input (but never
  663. within a string or character constant).  Such a line means that the
  664. following line originated in file FILENAME at line LINENUM.
  665.  
  666. The third field, FLAG, may be a number, or may be absent.  It is `1'
  667. for the beginning of a new source file, and `2' for return to an old
  668. source file at the end of an included file.  It is absent otherwise.
  669.  
  670.  
  671. 
  672. File: cpp.info,  Node: Invocation,  Next: Concept Index,  Prev: Output,  Up: Top
  673.  
  674. Invoking the C Preprocessor
  675. ===========================
  676.  
  677. Most often when you use the C preprocessor you will not have to
  678. invoke it explicitly: the C compiler will do so automatically. 
  679. However, the preprocessor is sometimes useful individually.
  680.  
  681. The C preprocessor expects two file names as arguments, INFILE and
  682. OUTFILE.  The preprocessor reads INFILE together with any other files
  683. it specifies with `#include'.  All the output generated by the
  684. combined input files is written in OUTFILE.
  685.  
  686. Either INFILE or OUTFILE may be `-', which as INFILE means to read
  687. from standard input and as OUTFILE means to write to standard output.
  688. Also, if OUTFILE or both file names are omitted, the standard output
  689. and standard input are used for the omitted file names.
  690.  
  691. Here is a table of command options accepted by the C preprocessor. 
  692. Most of them can also be given when compiling a C program; they are
  693. passed along automatically to the preprocessor when it is invoked by
  694. the compiler.
  695.  
  696. `-P'
  697.      Inhibit generation of `#'-lines with line-number information in
  698.      the output from the preprocessor (*note Output::.).  This might
  699.      be useful when running the preprocessor on something that is not
  700.      C code and will be sent to a program which might be confused by
  701.      the `#'-lines
  702.  
  703. `-C'
  704.      Do not discard comments: pass them through to the output file. 
  705.      Comments appearing in arguments of a macro call will be copied
  706.      to the output before the expansion of the macro call.
  707.  
  708. `-trigraphs'
  709.      Process ANSI standard trigraph sequences.  These are
  710.      three-character sequences, all starting with `??', that are
  711.      defined by ANSI C to stand for single characters.  For example,
  712.      `??/' stands for `\', so `'??/n'' is a character constant for a
  713.      newline.  Strictly speaking, the GNU C preprocessor does not
  714.      support all programs in ANSI Standard C unless `-trigraphs' is
  715.      used, but if you ever notice the difference it will be with
  716.      relief.
  717.  
  718.      You don't want to know any more about trigraphs.
  719.  
  720. `-pedantic'
  721.      Issue warnings required by the ANSI C standard in certain cases
  722.      such as when text other than a comment follows `#else' or
  723.      `#endif'.
  724.  
  725. `-I DIRECTORY'
  726.      Add the directory DIRECTORY to the end of the list of
  727.      directories to be searched for header files (*note Include
  728.      Syntax::.).  This can be used to override a system header file,
  729.      substituting your own version, since these directories are
  730.      searched before the system header file directories.  If you use
  731.      more than one `-I' option, the directories are scanned in
  732.      left-to-right order; the standard system directories come after.
  733.  
  734. `-I-'
  735.      Any directories specified with `-I' options before the `-I-'
  736.      option are searched only for the case of `#include "FILE"'; they
  737.      are not searched for `#include <FILE>'.
  738.  
  739.      If additional directories are specified with `-I' options after
  740.      the `-I-', these directories are searched for all `#include'
  741.      directives.
  742.  
  743.      In addition, the `-I-' option inhibits the use of the current
  744.      directory as the first search directory for `#include "FILE"'. 
  745.      Therefore, the current directory is searched only if it is
  746.      requested explicitly with `-I.'.  Specifying both `-I-' and
  747.      `-I.' allows you to control precisely which directories are
  748.      searched before the current one and which are searched after.
  749.  
  750. `-nostdinc'
  751.      Do not search the standard system directories for header files. 
  752.      Only the directories you have specified with `-I' options (and
  753.      the current directory, if appropriate) are searched.
  754.  
  755. `-D NAME'
  756.      Predefine NAME as a macro, with definition `1'.
  757.  
  758. `-D NAME=DEFINITION'
  759.      Predefine NAME as a macro, with definition DEFINITION.  There
  760.      are no restrictions on the contents of DEFINITION, but if you
  761.      are invoking the preprocessor from a shell or shell-like program
  762.      you may need to use the shell's quoting syntax to protect
  763.      characters such as spaces that have a meaning in the shell syntax.
  764.  
  765. `-U NAME'
  766.      Do not predefine NAME.  If both `-U' and `-D' are specified for
  767.      one name, the `-U' beats the `-D' and the name is not predefined.
  768.  
  769. `-undef'
  770.      Do not predefine any nonstandard macros.
  771.  
  772. `-d'
  773.      Instead of outputting the result of preprocessing, output a list
  774.      of `#define' commands for all the macros defined during the
  775.      execution of the preprocessor.
  776.  
  777. `-M'
  778.      Instead of outputting the result of preprocessing, output a rule
  779.      suitable for `make' describing the dependencies of the main
  780.      source file.  The preprocessor outputs one `make' rule
  781.      containing the object file name for that source file, a colon,
  782.      and the names of all the included files.  If there are many
  783.      included files then the rule is split into several lines using
  784.      `\'-newline.
  785.  
  786.      This feature is used in automatic updating of makefiles.
  787.  
  788. `-MM'
  789.      Like `-M' but mention only the files included with `#include
  790.      "FILE"'.  System header files included with `#include <FILE>'
  791.      are omitted.
  792.  
  793. `-i FILE'
  794.      Process FILE as input, discarding the resulting output, before
  795.      processing the regular input file.  Because the output generated
  796.      from FILE is discarded, the only effect of `-i FILE' is to make
  797.      the macros defined in FILE available for use in the main input.
  798.  
  799.  
  800. 
  801. File: cpp.info,  Node: Concept Index,  Next: Index,  Prev: Invocation,  Up: Top
  802.  
  803. Concept Index
  804. *************
  805.  
  806. * Menu:
  807.  
  808. * cascaded macros: Cascaded Macros.
  809. * commands: Commands.
  810. * concatenation: Concatenation.
  811. * conditionals: Conditionals.
  812. * header file: Header Files.
  813. * line control: Combining Sources.
  814. * macro body uses macro: Cascaded Macros.
  815. * null command: Other Commands.
  816. * options: Invocation.
  817. * output format: Output.
  818. * predefined macros: Predefined.
  819. * preprocessor commands: Commands.
  820. * redefining macros: Redefining.
  821. * repeated inclusion: Once-Only.
  822. * self-reference: Self-Reference.
  823. * semicolons (after macro calls): Swallow Semicolon.
  824. * side effects (in macro arguments): Side Effects.
  825. * stringification: Stringification.
  826. * undefining macros: Undefining.
  827. * unsafe macros: Side Effects.
  828.  
  829.  
  830.  
  831. 
  832. File: cpp.info,  Node: Index,  Prev: Concept Index,  Up: Top
  833.  
  834. Index of Commands, Macros and Options
  835. *************************************
  836.  
  837. * Menu:
  838.  
  839. * #elif: #elif Command.
  840. * #else: #else Command.
  841. * #error: #error Command.
  842. * #ident: Other Commands.
  843. * #if: Conditional Syntax.
  844. * #ifdef: Conditionals-Macros.
  845. * #ifndef: Conditionals-Macros.
  846. * #include: Include Syntax.
  847. * #line: Combining Sources.
  848. * #pragma: Other Commands.
  849. * -C: Invocation.
  850. * -D: Invocation.
  851. * -I: Invocation.
  852. * -M: Invocation.
  853. * -MM: Invocation.
  854. * -P: Invocation.
  855. * -U: Invocation.
  856. * -d: Invocation.
  857. * -i: Invocation.
  858. * -pedantic: Invocation.
  859. * -trigraphs: Invocation.
  860. * -undef: Invocation.
  861. * BSD: Nonstandard Predefined.
  862. * M68020: Nonstandard Predefined.
  863. * __BASE_FILE__: Standard Predefined.
  864. * __DATE__: Standard Predefined.
  865. * __FILE__: Standard Predefined.
  866. * __LINE__: Standard Predefined.
  867. * __STDC__: Standard Predefined.
  868. * __TIME__: Standard Predefined.
  869. * defined: Conditionals-Macros.
  870. * m68k: Nonstandard Predefined.
  871. * mc68000: Nonstandard Predefined.
  872. * ns32000: Nonstandard Predefined.
  873. * pyr: Nonstandard Predefined.
  874. * sequent: Nonstandard Predefined.
  875. * sun: Nonstandard Predefined.
  876. * system header files: Header Uses.
  877. * unix: Nonstandard Predefined.
  878. * vax: Nonstandard Predefined.
  879.  
  880.  
  881.  
  882.