home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / gcc / gcc261a.zoo / info / cpp next >
Encoding:
GNU Info File  |  1994-10-31  |  106.0 KB  |  2,646 lines

  1. This is Info file cpp.info, produced by Makeinfo-1.55 from the input
  2. file cpp.texi.
  3.  
  4.    This file documents the GNU C Preprocessor.
  5.  
  6.    Copyright 1987, 1989, 1991, 1992, 1993 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. File: cpp.info,  Node: Top,  Next: Global Actions,  Up: (DIR)
  22.  
  23. The C Preprocessor
  24. ******************
  25.  
  26.    The C preprocessor is a "macro processor" that is used automatically
  27. by the C compiler to transform your program before actual compilation.
  28. It is called a macro processor because it allows you to define "macros",
  29. which are brief abbreviations for longer constructs.
  30.  
  31.    The C preprocessor provides four separate facilities that you can
  32. use as you see fit:
  33.  
  34.    * Inclusion of header files.  These are files of declarations that
  35.      can be substituted into your program.
  36.  
  37.    * Macro expansion.  You can define "macros", which are abbreviations
  38.      for arbitrary fragments of C code, and then the C preprocessor will
  39.      replace the macros with their definitions throughout the program.
  40.  
  41.    * Conditional compilation.  Using special preprocessor commands, you
  42.      can include or exclude parts of the program according to various
  43.      conditions.
  44.  
  45.    * Line control.  If you use a program to combine or rearrange source
  46.      files into an intermediate file which is then compiled, you can
  47.      use line control to inform the compiler of where each source line
  48.      originally came from.
  49.  
  50.    C preprocessors vary in some details.  This manual discusses the GNU
  51. C preprocessor, the C Compatible Compiler Preprocessor.  The GNU C
  52. preprocessor provides a superset of the features of ANSI Standard C.
  53.  
  54.    ANSI Standard C requires the rejection of many harmless constructs
  55. commonly used by today's C programs.  Such incompatibility would be
  56. inconvenient for users, so the GNU C preprocessor is configured to
  57. accept these constructs by default.  Strictly speaking, to get ANSI
  58. Standard C, you must use the options `-trigraphs', `-undef' and
  59. `-pedantic', but in practice the consequences of having strict ANSI
  60. Standard C make it undesirable to do this.  *Note Invocation::.
  61.  
  62. * Menu:
  63.  
  64. * Global Actions::    Actions made uniformly on all input files.
  65. * Commands::          General syntax of preprocessor commands.
  66. * Header Files::      How and why to use header files.
  67. * Macros::            How and why to use macros.
  68. * Conditionals::      How and why to use conditionals.
  69. * Combining Sources:: Use of line control when you combine source files.
  70. * Other Commands::    Miscellaneous preprocessor commands.
  71. * Output::            Format of output from the C preprocessor.
  72. * Invocation::        How to invoke the preprocessor; command options.
  73. * Concept Index::     Index of concepts and terms.
  74. * Index::             Index of commands, predefined macros and options.
  75.  
  76. File: cpp.info,  Node: Global Actions,  Next: Commands,  Prev: Top,  Up: Top
  77.  
  78. Transformations Made Globally
  79. =============================
  80.  
  81.    Most C preprocessor features are inactive unless you give specific
  82. commands to request their use.  (Preprocessor commands are lines
  83. starting with `#'; *note Commands::.).  But there are three
  84. transformations that the preprocessor always makes on all the input it
  85. receives, even in the absence of commands.
  86.  
  87.    * All C comments are replaced with single spaces.
  88.  
  89.    * Backslash-Newline sequences are deleted, no matter where.  This
  90.      feature allows you to break long lines for cosmetic purposes
  91.      without changing their meaning.
  92.  
  93.    * Predefined macro names are replaced with their expansions (*note
  94.      Predefined::.).
  95.  
  96.    The first two transformations are done *before* nearly all other
  97. parsing and before preprocessor commands are recognized.  Thus, for
  98. example, you can split a line cosmetically with Backslash-Newline
  99. anywhere (except when trigraphs are in use; see below).
  100.  
  101.      /*
  102.      */ # /*
  103.      */ defi\
  104.      ne FO\
  105.      O 10\
  106.      20
  107.  
  108. is equivalent into `#define FOO 1020'.  You can split even an escape
  109. sequence with Backslash-Newline.  For example, you can split `"foo\bar"'
  110. between the `\' and the `b' to get
  111.  
  112.      "foo\\
  113.      bar"
  114.  
  115. This behavior is unclean: in all other contexts, a Backslash can be
  116. inserted in a string constant as an ordinary character by writing a
  117. double Backslash, and this creates an exception.  But the ANSI C
  118. standard requires it.  (Strict ANSI C does not allow Newlines in string
  119. constants, so they do not consider this a problem.)
  120.  
  121.    But there are a few exceptions to all three transformations.
  122.  
  123.    * C comments and predefined macro names are not recognized inside a
  124.      `#include' command in which the file name is delimited with `<'
  125.      and `>'.
  126.  
  127.    * C comments and predefined macro names are never recognized within a
  128.      character or string constant.  (Strictly speaking, this is the
  129.      rule, not an exception, but it is worth noting here anyway.)
  130.  
  131.    * Backslash-Newline may not safely be used within an ANSI "trigraph".
  132.      Trigraphs are converted before Backslash-Newline is deleted.  If
  133.      you write what looks like a trigraph with a Backslash-Newline
  134.      inside, the Backslash-Newline is deleted as usual, but it is then
  135.      too late to recognize the trigraph.
  136.  
  137.      This exception is relevant only if you use the `-trigraphs' option
  138.      to enable trigraph processing.  *Note Invocation::.
  139.  
  140. File: cpp.info,  Node: Commands,  Next: Header Files,  Prev: Global Actions,  Up: Top
  141.  
  142. Preprocessor Commands
  143. =====================
  144.  
  145.    Most preprocessor features are active only if you use preprocessor
  146. commands to request their use.
  147.  
  148.    Preprocessor commands are lines in your program that start with `#'.
  149. The `#' is followed by an identifier that is the "command name".  For
  150. example, `#define' is the command that defines a macro.  Whitespace is
  151. also allowed before and after the `#'.
  152.  
  153.    The set of valid command names is fixed.  Programs cannot define new
  154. preprocessor commands.
  155.  
  156.    Some command names require arguments; these make up the rest of the
  157. command line and must be separated from the command name by whitespace.
  158. For example, `#define' must be followed by a macro name and the
  159. intended expansion of the macro.  *Note Simple Macros::.
  160.  
  161.    A preprocessor command cannot be more than one line in normal
  162. circumstances.  It may be split cosmetically with Backslash-Newline,
  163. but that has no effect on its meaning.  Comments containing Newlines
  164. can also divide the command into multiple lines, but the comments are
  165. changed to Spaces before the command is interpreted.  The only way a
  166. significant Newline can occur in a preprocessor command is within a
  167. string constant or character constant.  Note that most C compilers that
  168. might be applied to the output from the preprocessor do not accept
  169. string or character constants containing Newlines.
  170.  
  171.    The `#' and the command name cannot come from a macro expansion.  For
  172. example, if `foo' is defined as a macro expanding to `define', that
  173. does not make `#foo' a valid preprocessor command.
  174.  
  175. File: cpp.info,  Node: Header Files,  Next: Macros,  Prev: Commands,  Up: Top
  176.  
  177. Header Files
  178. ============
  179.  
  180.    A header file is a file containing C declarations and macro
  181. definitions (*note Macros::.) to be shared between several source
  182. files.  You request the use of a header file in your program with the C
  183. preprocessor command `#include'.
  184.  
  185. * Menu:
  186.  
  187. * Header Uses::         What header files are used for.
  188. * Include Syntax::      How to write `#include' commands.
  189. * Include Operation::   What `#include' does.
  190. * Once-Only::        Preventing multiple inclusion of one header file.
  191. * Inheritance::         Including one header file in another header file.
  192.  
  193. File: cpp.info,  Node: Header Uses,  Next: Include Syntax,  Prev: Header Files,  Up: Header Files
  194.  
  195. Uses of Header Files
  196. --------------------
  197.  
  198.    Header files serve two kinds of purposes.
  199.  
  200.    * System header files declare the interfaces to parts of the
  201.      operating system.  You include them in your program to supply the
  202.      definitions and declarations you need to invoke system calls and
  203.      libraries.
  204.  
  205.    * Your own header files contain declarations for interfaces between
  206.      the source files of your program.  Each time you have a group of
  207.      related declarations and macro definitions all or most of which
  208.      are needed in several different source files, it is a good idea to
  209.      create a header file for them.
  210.  
  211.    Including a header file produces the same results in C compilation as
  212. copying the header file into each source file that needs it.  But such
  213. copying would be time-consuming and error-prone.  With a header file,
  214. the related declarations appear in only one place.  If they need to be
  215. changed, they can be changed in one place, and programs that include
  216. the header file will automatically use the new version when next
  217. recompiled.  The header file eliminates the labor of finding and
  218. changing all the copies as well as the risk that a failure to find one
  219. copy will result in inconsistencies within a program.
  220.  
  221.    The usual convention is to give header files names that end with
  222. `.h'.  Avoid unusual characters in header file names, as they reduce
  223. portability.
  224.  
  225. File: cpp.info,  Node: Include Syntax,  Next: Include Operation,  Prev: Header Uses,  Up: Header Files
  226.  
  227. The `#include' Command
  228. ----------------------
  229.  
  230.    Both user and system header files are included using the preprocessor
  231. command `#include'.  It has three variants:
  232.  
  233. `#include <FILE>'
  234.      This variant is used for system header files.  It searches for a
  235.      file named FILE in a list of directories specified by you, then in
  236.      a standard list of system directories.  You specify directories to
  237.      search for header files with the command option `-I' (*note
  238.      Invocation::.).  The option `-nostdinc' inhibits searching the
  239.      standard system directories; in this case only the directories you
  240.      specify are searched.
  241.  
  242.      The parsing of this form of `#include' is slightly special because
  243.      comments are not recognized within the `<...>'.  Thus, in
  244.      `#include <x/*y>' the `/*' does not start a comment and the
  245.      command specifies inclusion of a system header file named `x/*y'.
  246.      Of course, a header file with such a name is unlikely to exist on
  247.      Unix, where shell wildcard features would make it hard to
  248.      manipulate.
  249.  
  250.      The argument FILE may not contain a `>' character.  It may,
  251.      however, contain a `<' character.
  252.  
  253. `#include "FILE"'
  254.      This variant is used for header files of your own program.  It
  255.      searches for a file named FILE first in the current directory,
  256.      then in the same directories used for system header files.  The
  257.      current directory is the directory of the current input file.  It
  258.      is tried first because it is presumed to be the location of the
  259.      files that the current input file refers to.  (If the `-I-' option
  260.      is used, the special treatment of the current directory is
  261.      inhibited.)
  262.  
  263.      The argument FILE may not contain `"' characters.  If backslashes
  264.      occur within FILE, they are considered ordinary text characters,
  265.      not escape characters.  None of the character escape sequences
  266.      appropriate to string constants in C are processed.  Thus,
  267.      `#include "x\n\\y"' specifies a filename containing three
  268.      backslashes.  It is not clear why this behavior is ever useful, but
  269.      the ANSI standard specifies it.
  270.  
  271. `#include ANYTHING ELSE'
  272.      This variant is called a "computed #include".  Any `#include'
  273.      command whose argument does not fit the above two forms is a
  274.      computed include.  The text ANYTHING ELSE is checked for macro
  275.      calls, which are expanded (*note Macros::.).  When this is done,
  276.      the result must fit one of the above two variants--in particular,
  277.      the expanded text must in the end be surrounded by either quotes
  278.      or angle braces.
  279.  
  280.      This feature allows you to define a macro which controls the file
  281.      name to be used at a later point in the program.  One application
  282.      of this is to allow a site-specific configuration file for your
  283.      program to specify the names of the system include files to be
  284.      used.  This can help in porting the program to various operating
  285.      systems in which the necessary system header files are found in
  286.      different places.
  287.  
  288. File: cpp.info,  Node: Include Operation,  Next: Once-Only,  Prev: Include Syntax,  Up: Header Files
  289.  
  290. How `#include' Works
  291. --------------------
  292.  
  293.    The `#include' command works by directing the C preprocessor to scan
  294. the specified file as input before continuing with the rest of the
  295. current file.  The output from the preprocessor contains the output
  296. already generated, followed by the output resulting from the included
  297. file, followed by the output that comes from the text after the
  298. `#include' command.  For example, given a header file `header.h' as
  299. follows,
  300.  
  301.      char *test ();
  302.  
  303. and a main program called `program.c' that uses the header file, like
  304. this,
  305.  
  306.      int x;
  307.      #include "header.h"
  308.      
  309.      main ()
  310.      {
  311.        printf (test ());
  312.      }
  313.  
  314. the output generated by the C preprocessor for `program.c' as input
  315. would be
  316.  
  317.      int x;
  318.      char *test ();
  319.      
  320.      main ()
  321.      {
  322.        printf (test ());
  323.      }
  324.  
  325.    Included files are not limited to declarations and macro
  326. definitions; those are merely the typical uses.  Any fragment of a C
  327. program can be included from another file.  The include file could even
  328. contain the beginning of a statement that is concluded in the
  329. containing file, or the end of a statement that was started in the
  330. including file.  However, a comment or a string or character constant
  331. may not start in the included file and finish in the including file.
  332. An unterminated comment, string constant or character constant in an
  333. included file is considered to end (with an error message) at the end
  334. of the file.
  335.  
  336.    It is possible for a header file to begin or end a syntactic unit
  337. such as a function definition, but that would be very confusing, so
  338. don't do it.
  339.  
  340.    The line following the `#include' command is always treated as a
  341. separate line by the C preprocessor even if the included file lacks a
  342. final newline.
  343.  
  344. File: cpp.info,  Node: Once-Only,  Next: Inheritance,  Prev: Include Operation,  Up: Header Files
  345.  
  346. Once-Only Include Files
  347. -----------------------
  348.  
  349.    Very often, one header file includes another.  It can easily result
  350. that a certain header file is included more than once.  This may lead
  351. to errors, if the header file defines structure types or typedefs, and
  352. is certainly wasteful.  Therefore, we often wish to prevent multiple
  353. inclusion of a header file.
  354.  
  355.    The standard way to do this is to enclose the entire real contents
  356. of the file in a conditional, like this:
  357.  
  358.      #ifndef FILE_FOO_SEEN
  359.      #define FILE_FOO_SEEN
  360.      
  361.      THE ENTIRE FILE
  362.      
  363.      #endif /* FILE_FOO_SEEN */
  364.  
  365.    The macro `FILE_FOO_SEEN' indicates that the file has been included
  366. once already.  In a user header file, the macro name should not begin
  367. with `_'.  In a system header file, this name should begin with `__' to
  368. avoid conflicts with user programs.  In any kind of header file, the
  369. macro name should contain the name of the file and some additional
  370. text, to avoid conflicts with other header files.
  371.  
  372.    The GNU C preprocessor is programmed to notice when a header file
  373. uses this particular construct and handle it efficiently.  If a header
  374. file is contained entirely in a `#ifndef' conditional, then it records
  375. that fact.  If a subsequent `#include' specifies the same file, and the
  376. macro in the `#ifndef' is already defined, then the file is entirely
  377. skipped, without even reading it.
  378.  
  379.    There is also an explicit command to tell the preprocessor that it
  380. need not include a file more than once.  This is called `#pragma once',
  381. and was used *in addition to* the `#ifndef' conditional around the
  382. contents of the header file.  `#pragma once' is now obsolete and should
  383. not be used at all.
  384.  
  385.    In the Objective C language, there is a variant of `#include' called
  386. `#import' which includes a file, but does so at most once.  If you use
  387. `#import' *instead of* `#include', then you don't need the conditionals
  388. inside the header file to prevent multiple execution of the contents.
  389.  
  390.    `#import' is obsolete because it is not a well designed feature.  It
  391. requires the users of a header file--the applications programmers--to
  392. know that a certain header file should only be included once.  It is
  393. much better for the header file's implementor to write the file so that
  394. users don't need to know this.  Using `#ifndef' accomplishes this goal.
  395.  
  396. File: cpp.info,  Node: Inheritance,  Prev: Once-Only,  Up: Header Files
  397.  
  398. Inheritance and Header Files
  399. ----------------------------
  400.  
  401.    "Inheritance" is what happens when one object or file derives some
  402. of its contents by virtual copying from another object or file.  In the
  403. case of C header files, inheritance means that one header file includes
  404. another header file and then replaces or adds something.
  405.  
  406.    If the inheriting header file and the base header file have different
  407. names, then inheritance is straightforward: simply write `#include
  408. "BASE"' in the inheriting file.
  409.  
  410.    Sometimes it is necessary to give the inheriting file the same name
  411. as the base file.  This is less straightforward.
  412.  
  413.    For example, suppose an application program uses the system header
  414. file `sys/signal.h', but the version of `/usr/include/sys/signal.h' on
  415. a particular system doesn't do what the application program expects.
  416. It might be convenient to define a "local" version, perhaps under the
  417. name `/usr/local/include/sys/signal.h', to override or add to the one
  418. supplied by the system.
  419.  
  420.    You can do this by using the option `-I.' for compilation, and
  421. writing a file `sys/signal.h' that does what the application program
  422. expects.  But making this file include the standard `sys/signal.h' is
  423. not so easy--writing `#include <sys/signal.h>' in that file doesn't
  424. work, because it includes your own version of the file, not the
  425. standard system version.  Used in that file itself, this leads to an
  426. infinite recursion and a fatal error in compilation.
  427.  
  428.    `#include </usr/include/sys/signal.h>' would find the proper file,
  429. but that is not clean, since it makes an assumption about where the
  430. system header file is found.  This is bad for maintenance, since it
  431. means that any change in where the system's header files are kept
  432. requires a change somewhere else.
  433.  
  434.    The clean way to solve this problem is to use `#include_next', which
  435. means, "Include the *next* file with this name."  This command works
  436. like `#include' except in searching for the specified file: it starts
  437. searching the list of header file directories *after* the directory in
  438. which the current file was found.
  439.  
  440.    Suppose you specify `-I /usr/local/include', and the list of
  441. directories to search also includes `/usr/include'; and suppose that
  442. both directories contain a file named `sys/signal.h'.  Ordinary
  443. `#include <sys/signal.h>' finds the file under `/usr/local/include'.
  444. If that file contains `#include_next <sys/signal.h>', it starts
  445. searching after that directory, and finds the file in `/usr/include'.
  446.  
  447. File: cpp.info,  Node: Macros,  Next: Conditionals,  Prev: Header Files,  Up: Top
  448.  
  449. Macros
  450. ======
  451.  
  452.    A macro is a sort of abbreviation which you can define once and then
  453. use later.  There are many complicated features associated with macros
  454. in the C preprocessor.
  455.  
  456. * Menu:
  457.  
  458. * Simple Macros::    Macros that always expand the same way.
  459. * Argument Macros::  Macros that accept arguments that are substituted
  460.                        into the macro expansion.
  461. * Predefined::       Predefined macros that are always available.
  462. * Stringification::  Macro arguments converted into string constants.
  463. * Concatenation::    Building tokens from parts taken from macro arguments.
  464. * Undefining::       Cancelling a macro's definition.
  465. * Redefining::       Changing a macro's definition.
  466. * Macro Pitfalls::   Macros can confuse the unwary.  Here we explain
  467.                        several common problems and strange features.
  468.  
  469. File: cpp.info,  Node: Simple Macros,  Next: Argument Macros,  Prev: Macros,  Up: Macros
  470.  
  471. Simple Macros
  472. -------------
  473.  
  474.    A "simple macro" is a kind of abbreviation.  It is a name which
  475. stands for a fragment of code.  Some people refer to these as "manifest
  476. constants".
  477.  
  478.    Before you can use a macro, you must "define" it explicitly with the
  479. `#define' command.  `#define' is followed by the name of the macro and
  480. then the code it should be an abbreviation for.  For example,
  481.  
  482.      #define BUFFER_SIZE 1020
  483.  
  484. defines a macro named `BUFFER_SIZE' as an abbreviation for the text
  485. `1020'.  If somewhere after this `#define' command there comes a C
  486. statement of the form
  487.  
  488.      foo = (char *) xmalloc (BUFFER_SIZE);
  489.  
  490. then the C preprocessor will recognize and "expand" the macro
  491. `BUFFER_SIZE', resulting in
  492.  
  493.      foo = (char *) xmalloc (1020);
  494.  
  495.    The use of all upper case for macro names is a standard convention.
  496. Programs are easier to read when it is possible to tell at a glance
  497. which names are macros.
  498.  
  499.    Normally, a macro definition must be a single line, like all C
  500. preprocessor commands.  (You can split a long macro definition
  501. cosmetically with Backslash-Newline.)  There is one exception: Newlines
  502. can be included in the macro definition if within a string or character
  503. constant.  This is because it is not possible for a macro definition to
  504. contain an unbalanced quote character; the definition automatically
  505. extends to include the matching quote character that ends the string or
  506. character constant.  Comments within a macro definition may contain
  507. Newlines, which make no difference since the comments are entirely
  508. replaced with Spaces regardless of their contents.
  509.  
  510.    Aside from the above, there is no restriction on what can go in a
  511. macro body.  Parentheses need not balance.  The body need not resemble
  512. valid C code.  (But if it does not, you may get error messages from the
  513. C compiler when you use the macro.)
  514.  
  515.    The C preprocessor scans your program sequentially, so macro
  516. definitions take effect at the place you write them.  Therefore, the
  517. following input to the C preprocessor
  518.  
  519.      foo = X;
  520.      #define X 4
  521.      bar = X;
  522.  
  523. produces as output
  524.  
  525.      foo = X;
  526.      
  527.      bar = 4;
  528.  
  529.    After the preprocessor expands a macro name, the macro's definition
  530. body is appended to the front of the remaining input, and the check for
  531. macro calls continues.  Therefore, the macro body can contain calls to
  532. other macros.  For example, after
  533.  
  534.      #define BUFSIZE 1020
  535.      #define TABLESIZE BUFSIZE
  536.  
  537. the name `TABLESIZE' when used in the program would go through two
  538. stages of expansion, resulting ultimately in `1020'.
  539.  
  540.    This is not at all the same as defining `TABLESIZE' to be `1020'.
  541. The `#define' for `TABLESIZE' uses exactly the body you specify--in
  542. this case, `BUFSIZE'--and does not check to see whether it too is the
  543. name of a macro.  It's only when you *use* `TABLESIZE' that the result
  544. of its expansion is checked for more macro names.  *Note Cascaded
  545. Macros::.
  546.  
  547. File: cpp.info,  Node: Argument Macros,  Next: Predefined,  Prev: Simple Macros,  Up: Macros
  548.  
  549. Macros with Arguments
  550. ---------------------
  551.  
  552.    A simple macro always stands for exactly the same text, each time it
  553. is used.  Macros can be more flexible when they accept "arguments".
  554. Arguments are fragments of code that you supply each time the macro is
  555. used.  These fragments are included in the expansion of the macro
  556. according to the directions in the macro definition.  A macro that
  557. accepts arguments is called a "function-like macro" because the syntax
  558. for using it looks like a function call.
  559.  
  560.    To define a macro that uses arguments, you write a `#define' command
  561. with a list of "argument names" in parentheses after the name of the
  562. macro.  The argument names may be any valid C identifiers, separated by
  563. commas and optionally whitespace.  The open-parenthesis must follow the
  564. macro name immediately, with no space in between.
  565.  
  566.    For example, here is a macro that computes the minimum of two numeric
  567. values, as it is defined in many C programs:
  568.  
  569.      #define min(X, Y)  ((X) < (Y) ? (X) : (Y))
  570.  
  571. (This is not the best way to define a "minimum" macro in GNU C.  *Note
  572. Side Effects::, for more information.)
  573.  
  574.    To use a macro that expects arguments, you write the name of the
  575. macro followed by a list of "actual arguments" in parentheses,
  576. separated by commas.  The number of actual arguments you give must
  577. match the number of arguments the macro expects.   Examples of use of
  578. the macro `min' include `min (1, 2)' and `min (x + 28, *p)'.
  579.  
  580.    The expansion text of the macro depends on the arguments you use.
  581. Each of the argument names of the macro is replaced, throughout the
  582. macro definition, with the corresponding actual argument.  Using the
  583. same macro `min' defined above, `min (1, 2)' expands into
  584.  
  585.      ((1) < (2) ? (1) : (2))
  586.  
  587. where `1' has been substituted for `X' and `2' for `Y'.
  588.  
  589.    Likewise, `min (x + 28, *p)' expands into
  590.  
  591.      ((x + 28) < (*p) ? (x + 28) : (*p))
  592.  
  593.    Parentheses in the actual arguments must balance; a comma within
  594. parentheses does not end an argument.  However, there is no requirement
  595. for brackets or braces to balance, and they do not prevent a comma from
  596. separating arguments.  Thus,
  597.  
  598.      macro (array[x = y, x + 1])
  599.  
  600. passes two arguments to `macro': `array[x = y' and `x + 1]'.  If you
  601. want to supply `array[x = y, x + 1]' as an argument, you must write it
  602. as `array[(x = y, x + 1)]', which is equivalent C code.
  603.  
  604.    After the actual arguments are substituted into the macro body, the
  605. entire result is appended to the front of the remaining input, and the
  606. check for macro calls continues.  Therefore, the actual arguments can
  607. contain calls to other macros, either with or without arguments, or
  608. even to the same macro.  The macro body can also contain calls to other
  609. macros.  For example, `min (min (a, b), c)' expands into this text:
  610.  
  611.      ((((a) < (b) ? (a) : (b))) < (c)
  612.       ? (((a) < (b) ? (a) : (b)))
  613.       : (c))
  614.  
  615. (Line breaks shown here for clarity would not actually be generated.)
  616.  
  617.    If a macro `foo' takes one argument, and you want to supply an empty
  618. argument, you must write at least some whitespace between the
  619. parentheses, like this: `foo ( )'.  Just `foo ()' is providing no
  620. arguments, which is an error if `foo' expects an argument.  But `foo0
  621. ()' is the correct way to call a macro defined to take zero arguments,
  622. like this:
  623.  
  624.      #define foo0() ...
  625.  
  626.    If you use the macro name followed by something other than an
  627. open-parenthesis (after ignoring any spaces, tabs and comments that
  628. follow), it is not a call to the macro, and the preprocessor does not
  629. change what you have written.  Therefore, it is possible for the same
  630. name to be a variable or function in your program as well as a macro,
  631. and you can choose in each instance whether to refer to the macro (if
  632. an actual argument list follows) or the variable or function (if an
  633. argument list does not follow).
  634.  
  635.    Such dual use of one name could be confusing and should be avoided
  636. except when the two meanings are effectively synonymous: that is, when
  637. the name is both a macro and a function and the two have similar
  638. effects.  You can think of the name simply as a function; use of the
  639. name for purposes other than calling it (such as, to take the address)
  640. will refer to the function, while calls will expand the macro and
  641. generate better but equivalent code.  For example, you can use a
  642. function named `min' in the same source file that defines the macro.
  643. If you write `&min' with no argument list, you refer to the function.
  644. If you write `min (x, bb)', with an argument list, the macro is
  645. expanded.  If you write `(min) (a, bb)', where the name `min' is not
  646. followed by an open-parenthesis, the macro is not expanded, so you wind
  647. up with a call to the function `min'.
  648.  
  649.    You may not define the same name as both a simple macro and a macro
  650. with arguments.
  651.  
  652.    In the definition of a macro with arguments, the list of argument
  653. names must follow the macro name immediately with no space in between.
  654. If there is a space after the macro name, the macro is defined as
  655. taking no arguments, and all the rest of the line is taken to be the
  656. expansion.  The reason for this is that it is often useful to define a
  657. macro that takes no arguments and whose definition begins with an
  658. identifier in parentheses.  This rule about spaces makes it possible
  659. for you to do either this:
  660.  
  661.      #define FOO(x) - 1 / (x)
  662.  
  663. (which defines `FOO' to take an argument and expand into minus the
  664. reciprocal of that argument) or this:
  665.  
  666.      #define BAR (x) - 1 / (x)
  667.  
  668. (which defines `BAR' to take no argument and always expand into `(x) -
  669. 1 / (x)').
  670.  
  671.    Note that the *uses* of a macro with arguments can have spaces before
  672. the left parenthesis; it's the *definition* where it matters whether
  673. there is a space.
  674.  
  675. File: cpp.info,  Node: Predefined,  Next: Stringification,  Prev: Argument Macros,  Up: Macros
  676.  
  677. Predefined Macros
  678. -----------------
  679.  
  680.    Several simple macros are predefined.  You can use them without
  681. giving definitions for them.  They fall into two classes: standard
  682. macros and system-specific macros.
  683.  
  684. * Menu:
  685.  
  686. * Standard Predefined::     Standard predefined macros.
  687. * Nonstandard Predefined::  Nonstandard predefined macros.
  688.  
  689. File: cpp.info,  Node: Standard Predefined,  Next: Nonstandard Predefined,  Prev: Predefined,  Up: Predefined
  690.  
  691. Standard Predefined Macros
  692. ..........................
  693.  
  694.    The standard predefined macros are available with the same meanings
  695. regardless of the machine or operating system on which you are using
  696. GNU C.  Their names all start and end with double underscores.  Those
  697. preceding `__GNUC__' in this table are standardized by ANSI C; the rest
  698. are GNU C extensions.
  699.  
  700. `__FILE__'
  701.      This macro expands to the name of the current input file, in the
  702.      form of a C string constant.  The precise name returned is the one
  703.      that was specified in `#include' or as the input file name
  704.      argument.
  705.  
  706. `__LINE__'
  707.      This macro expands to the current input line number, in the form
  708.      of a decimal integer constant.  While we call it a predefined
  709.      macro, it's a pretty strange macro, since its "definition" changes
  710.      with each new line of source code.
  711.  
  712.      This and `__FILE__' are useful in generating an error message to
  713.      report an inconsistency detected by the program; the message can
  714.      state the source line at which the inconsistency was detected.
  715.      For example,
  716.  
  717.           fprintf (stderr, "Internal error: "
  718.                            "negative string length "
  719.                            "%d at %s, line %d.",
  720.                    length, __FILE__, __LINE__);
  721.  
  722.      A `#include' command changes the expansions of `__FILE__' and
  723.      `__LINE__' to correspond to the included file.  At the end of that
  724.      file, when processing resumes on the input file that contained the
  725.      `#include' command, the expansions of `__FILE__' and `__LINE__'
  726.      revert to the values they had before the `#include' (but
  727.      `__LINE__' is then incremented by one as processing moves to the
  728.      line after the `#include').
  729.  
  730.      The expansions of both `__FILE__' and `__LINE__' are altered if a
  731.      `#line' command is used.  *Note Combining Sources::.
  732.  
  733. `__INCLUDE_LEVEL__'
  734.      This macro expands to a decimal integer constant that represents
  735.      the depth of nesting in include files.  The value of this macro is
  736.      incremented on every `#include' command and decremented at every
  737.      end of file.  For input files specified by command line arguments,
  738.      the nesting level is zero.
  739.  
  740. `__DATE__'
  741.      This macro expands to a string constant that describes the date on
  742.      which the preprocessor is being run.  The string constant contains
  743.      eleven characters and looks like `"Jan 29 1987"' or `"Apr 1 1905"'.
  744.  
  745. `__TIME__'
  746.      This macro expands to a string constant that describes the time at
  747.      which the preprocessor is being run.  The string constant contains
  748.      eight characters and looks like `"23:59:01"'.
  749.  
  750. `__STDC__'
  751.      This macro expands to the constant 1, to signify that this is ANSI
  752.      Standard C.  (Whether that is actually true depends on what C
  753.      compiler will operate on the output from the preprocessor.)
  754.  
  755. `__GNUC__'
  756.      This macro is defined if and only if this is GNU C.  This macro is
  757.      defined only when the entire GNU C compiler is in use; if you
  758.      invoke the preprocessor directly, `__GNUC__' is undefined.  The
  759.      value identifies the major version number of GNU CC (`1' for GNU CC
  760.      version 1, which is now obsolete, and `2' for version 2).
  761.  
  762. `__GNUG__'
  763.      The GNU C compiler defines this when the compilation language is
  764.      C++; use `__GNUG__' to distinguish between GNU C and GNU C++.
  765.  
  766. `__cplusplus'
  767.      The draft ANSI standard for C++ used to require predefining this
  768.      variable.  Though it is no longer required, GNU C++ continues to
  769.      define it, as do other popular C++ compilers.  You can use
  770.      `__cplusplus' to test whether a header is compiled by a C compiler
  771.      or a C++ compiler.
  772.  
  773. `__STRICT_ANSI__'
  774.      This macro is defined if and only if the `-ansi' switch was
  775.      specified when GNU C was invoked.  Its definition is the null
  776.      string.  This macro exists primarily to direct certain GNU header
  777.      files not to define certain traditional Unix constructs which are
  778.      incompatible with ANSI C.
  779.  
  780. `__BASE_FILE__'
  781.      This macro expands to the name of the main input file, in the form
  782.      of a C string constant.  This is the source file that was specified
  783.      as an argument when the C compiler was invoked.
  784.  
  785. `__VERSION__'
  786.      This macro expands to a string which describes the version number
  787.      of GNU C.  The string is normally a sequence of decimal numbers
  788.      separated by periods, such as `"2.6.0"'.  The only reasonable use
  789.      of this macro is to incorporate it into a string constant.
  790.  
  791. `__OPTIMIZE__'
  792.      This macro is defined in optimizing compilations.  It causes
  793.      certain GNU header files to define alternative macro definitions
  794.      for some system library functions.  It is unwise to refer to or
  795.      test the definition of this macro unless you make very sure that
  796.      programs will execute with the same effect regardless.
  797.  
  798. `__CHAR_UNSIGNED__'
  799.      This macro is defined if and only if the data type `char' is
  800.      unsigned on the target machine.  It exists to cause the standard
  801.      header file `limit.h' to work correctly.  It is bad practice to
  802.      refer to this macro yourself; instead, refer to the standard
  803.      macros defined in `limit.h'.  The preprocessor uses this macro to
  804.      determine whether or not to sign-extend large character constants
  805.      written in octal; see *Note The `#if' Command: #if Command.
  806.  
  807. File: cpp.info,  Node: Nonstandard Predefined,  Prev: Standard Predefined,  Up: Predefined
  808.  
  809. Nonstandard Predefined Macros
  810. .............................
  811.  
  812.    The C preprocessor normally has several predefined macros that vary
  813. between machines because their purpose is to indicate what type of
  814. system and machine is in use.  This manual, being for all systems and
  815. machines, cannot tell you exactly what their names are; instead, we
  816. offer a list of some typical ones.  You can use `cpp -dM' to see the
  817. values of predefined macros; see *Note Invocation::.
  818.  
  819.    Some nonstandard predefined macros describe the operating system in
  820. use, with more or less specificity.  For example,
  821.  
  822. `unix'
  823.      `unix' is normally predefined on all Unix systems.
  824.  
  825. `BSD'
  826.      `BSD' is predefined on recent versions of Berkeley Unix (perhaps
  827.      only in version 4.3).
  828.  
  829.    Other nonstandard predefined macros describe the kind of CPU, with
  830. more or less specificity.  For example,
  831.  
  832. `vax'
  833.      `vax' is predefined on Vax computers.
  834.  
  835. `mc68000'
  836.      `mc68000' is predefined on most computers whose CPU is a Motorola
  837.      68000, 68010 or 68020.
  838.  
  839. `m68k'
  840.      `m68k' is also predefined on most computers whose CPU is a 68000,
  841.      68010 or 68020; however, some makers use `mc68000' and some use
  842.      `m68k'.  Some predefine both names.  What happens in GNU C depends
  843.      on the system you are using it on.
  844.  
  845. `M68020'
  846.      `M68020' has been observed to be predefined on some systems that
  847.      use 68020 CPUs--in addition to `mc68000' and `m68k', which are
  848.      less specific.
  849.  
  850. `_AM29K'
  851. `_AM29000'
  852.      Both `_AM29K' and `_AM29000' are predefined for the AMD 29000 CPU
  853.      family.
  854.  
  855. `ns32000'
  856.      `ns32000' is predefined on computers which use the National
  857.      Semiconductor 32000 series CPU.
  858.  
  859.    Yet other nonstandard predefined macros describe the manufacturer of
  860. the system.  For example,
  861.  
  862. `sun'
  863.      `sun' is predefined on all models of Sun computers.
  864.  
  865. `pyr'
  866.      `pyr' is predefined on all models of Pyramid computers.
  867.  
  868. `sequent'
  869.      `sequent' is predefined on all models of Sequent computers.
  870.  
  871.    These predefined symbols are not only nonstandard, they are contrary
  872. to the ANSI standard because their names do not start with underscores.
  873. Therefore, the option `-ansi' inhibits the definition of these symbols.
  874.  
  875.    This tends to make `-ansi' useless, since many programs depend on the
  876. customary nonstandard predefined symbols.  Even system header files
  877. check them and will generate incorrect declarations if they do not find
  878. the names that are expected.  You might think that the header files
  879. supplied for the Uglix computer would not need to test what machine
  880. they are running on, because they can simply assume it is the Uglix;
  881. but often they do, and they do so using the customary names.  As a
  882. result, very few C programs will compile with `-ansi'.  We intend to
  883. avoid such problems on the GNU system.
  884.  
  885.    What, then, should you do in an ANSI C program to test the type of
  886. machine it will run on?
  887.  
  888.    GNU C offers a parallel series of symbols for this purpose, whose
  889. names are made from the customary ones by adding `__' at the beginning
  890. and end.  Thus, the symbol `__vax__' would be available on a Vax, and
  891. so on.
  892.  
  893.    The set of nonstandard predefined names in the GNU C preprocessor is
  894. controlled (when `cpp' is itself compiled) by the macro
  895. `CPP_PREDEFINES', which should be a string containing `-D' options,
  896. separated by spaces.  For example, on the Sun 3, we use the following
  897. definition:
  898.  
  899.      #define CPP_PREDEFINES "-Dmc68000 -Dsun -Dunix -Dm68k"
  900.  
  901. This macro is usually specified in `tm.h'.
  902.  
  903. File: cpp.info,  Node: Stringification,  Next: Concatenation,  Prev: Predefined,  Up: Macros
  904.  
  905. Stringification
  906. ---------------
  907.  
  908.    "Stringification" means turning a code fragment into a string
  909. constant whose contents are the text for the code fragment.  For
  910. example, stringifying `foo (z)' results in `"foo (z)"'.
  911.  
  912.    In the C preprocessor, stringification is an option available when
  913. macro arguments are substituted into the macro definition.  In the body
  914. of the definition, when an argument name appears, the character `#'
  915. before the name specifies stringification of the corresponding actual
  916. argument when it is substituted at that point in the definition.  The
  917. same argument may be substituted in other places in the definition
  918. without stringification if the argument name appears in those places
  919. with no `#'.
  920.  
  921.    Here is an example of a macro definition that uses stringification:
  922.  
  923.      #define WARN_IF(EXP) \
  924.      do { if (EXP) \
  925.              fprintf (stderr, "Warning: " #EXP "\n"); } \
  926.      while (0)
  927.  
  928. Here the actual argument for `EXP' is substituted once as given, into
  929. the `if' statement, and once as stringified, into the argument to
  930. `fprintf'.  The `do' and `while (0)' are a kludge to make it possible
  931. to write `WARN_IF (ARG);', which the resemblance of `WARN_IF' to a
  932. function would make C programmers want to do; see *Note Swallow
  933. Semicolon::.
  934.  
  935.    The stringification feature is limited to transforming one macro
  936. argument into one string constant: there is no way to combine the
  937. argument with other text and then stringify it all together.  But the
  938. example above shows how an equivalent result can be obtained in ANSI
  939. Standard C using the feature that adjacent string constants are
  940. concatenated as one string constant.  The preprocessor stringifies the
  941. actual value of `EXP' into a separate string constant, resulting in
  942. text like
  943.  
  944.      do { if (x == 0) \
  945.              fprintf (stderr, "Warning: " "x == 0" "\n"); } \
  946.      while (0)
  947.  
  948. but the C compiler then sees three consecutive string constants and
  949. concatenates them into one, producing effectively
  950.  
  951.      do { if (x == 0) \
  952.              fprintf (stderr, "Warning: x == 0\n"); } \
  953.      while (0)
  954.  
  955.    Stringification in C involves more than putting doublequote
  956. characters around the fragment; it is necessary to put backslashes in
  957. front of all doublequote characters, and all backslashes in string and
  958. character constants, in order to get a valid C string constant with the
  959. proper contents.  Thus, stringifying `p = "foo\n";' results in `"p =
  960. \"foo\\n\";"'.  However, backslashes that are not inside of string or
  961. character constants are not duplicated: `\n' by itself stringifies to
  962. `"\n"'.
  963.  
  964.    Whitespace (including comments) in the text being stringified is
  965. handled according to precise rules.  All leading and trailing
  966. whitespace is ignored.  Any sequence of whitespace in the middle of the
  967. text is converted to a single space in the stringified result.
  968.  
  969. File: cpp.info,  Node: Concatenation,  Next: Undefining,  Prev: Stringification,  Up: Macros
  970.  
  971. Concatenation
  972. -------------
  973.  
  974.    "Concatenation" means joining two strings into one.  In the context
  975. of macro expansion, concatenation refers to joining two lexical units
  976. into one longer one.  Specifically, an actual argument to the macro can
  977. be concatenated with another actual argument or with fixed text to
  978. produce a longer name.  The longer name might be the name of a function,
  979. variable or type, or a C keyword; it might even be the name of another
  980. macro, in which case it will be expanded.
  981.  
  982.    When you define a macro, you request concatenation with the special
  983. operator `##' in the macro body.  When the macro is called, after
  984. actual arguments are substituted, all `##' operators are deleted, and
  985. so is any whitespace next to them (including whitespace that was part
  986. of an actual argument).  The result is to concatenate the syntactic
  987. tokens on either side of the `##'.
  988.  
  989.    Consider a C program that interprets named commands.  There probably
  990. needs to be a table of commands, perhaps an array of structures
  991. declared as follows:
  992.  
  993.      struct command
  994.      {
  995.        char *name;
  996.        void (*function) ();
  997.      };
  998.      
  999.      struct command commands[] =
  1000.      {
  1001.        { "quit", quit_command},
  1002.        { "help", help_command},
  1003.        ...
  1004.      };
  1005.  
  1006.    It would be cleaner not to have to give each command name twice,
  1007. once in the string constant and once in the function name.  A macro
  1008. which takes the name of a command as an argument can make this
  1009. unnecessary.  The string constant can be created with stringification,
  1010. and the function name by concatenating the argument with `_command'.
  1011. Here is how it is done:
  1012.  
  1013.      #define COMMAND(NAME)  { #NAME, NAME ## _command }
  1014.      
  1015.      struct command commands[] =
  1016.      {
  1017.        COMMAND (quit),
  1018.        COMMAND (help),
  1019.        ...
  1020.      };
  1021.  
  1022.    The usual case of concatenation is concatenating two names (or a
  1023. name and a number) into a longer name.  But this isn't the only valid
  1024. case.  It is also possible to concatenate two numbers (or a number and
  1025. a name, such as `1.5' and `e3') into a number.  Also, multi-character
  1026. operators such as `+=' can be formed by concatenation.  In some cases
  1027. it is even possible to piece together a string constant.  However, two
  1028. pieces of text that don't together form a valid lexical unit cannot be
  1029. concatenated.  For example, concatenation with `x' on one side and `+'
  1030. on the other is not meaningful because those two characters can't fit
  1031. together in any lexical unit of C.  The ANSI standard says that such
  1032. attempts at concatenation are undefined, but in the GNU C preprocessor
  1033. it is well defined: it puts the `x' and `+' side by side with no
  1034. particular special results.
  1035.  
  1036.    Keep in mind that the C preprocessor converts comments to whitespace
  1037. before macros are even considered.  Therefore, you cannot create a
  1038. comment by concatenating `/' and `*': the `/*' sequence that starts a
  1039. comment is not a lexical unit, but rather the beginning of a "long"
  1040. space character.  Also, you can freely use comments next to a `##' in a
  1041. macro definition, or in actual arguments that will be concatenated,
  1042. because the comments will be converted to spaces at first sight, and
  1043. concatenation will later discard the spaces.
  1044.  
  1045. File: cpp.info,  Node: Undefining,  Next: Redefining,  Prev: Concatenation,  Up: Macros
  1046.  
  1047. Undefining Macros
  1048. -----------------
  1049.  
  1050.    To "undefine" a macro means to cancel its definition.  This is done
  1051. with the `#undef' command.  `#undef' is followed by the macro name to
  1052. be undefined.
  1053.  
  1054.    Like definition, undefinition occurs at a specific point in the
  1055. source file, and it applies starting from that point.  The name ceases
  1056. to be a macro name, and from that point on it is treated by the
  1057. preprocessor as if it had never been a macro name.
  1058.  
  1059.    For example,
  1060.  
  1061.      #define FOO 4
  1062.      x = FOO;
  1063.      #undef FOO
  1064.      x = FOO;
  1065.  
  1066. expands into
  1067.  
  1068.      x = 4;
  1069.      
  1070.      x = FOO;
  1071.  
  1072. In this example, `FOO' had better be a variable or function as well as
  1073. (temporarily) a macro, in order for the result of the expansion to be
  1074. valid C code.
  1075.  
  1076.    The same form of `#undef' command will cancel definitions with
  1077. arguments or definitions that don't expect arguments.  The `#undef'
  1078. command has no effect when used on a name not currently defined as a
  1079. macro.
  1080.  
  1081. File: cpp.info,  Node: Redefining,  Next: Macro Pitfalls,  Prev: Undefining,  Up: Macros
  1082.  
  1083. Redefining Macros
  1084. -----------------
  1085.  
  1086.    "Redefining" a macro means defining (with `#define') a name that is
  1087. already defined as a macro.
  1088.  
  1089.    A redefinition is trivial if the new definition is transparently
  1090. identical to the old one.  You probably wouldn't deliberately write a
  1091. trivial redefinition, but they can happen automatically when a header
  1092. file is included more than once (*note Header Files::.), so they are
  1093. accepted silently and without effect.
  1094.  
  1095.    Nontrivial redefinition is considered likely to be an error, so it
  1096. provokes a warning message from the preprocessor.  However, sometimes it
  1097. is useful to change the definition of a macro in mid-compilation.  You
  1098. can inhibit the warning by undefining the macro with `#undef' before the
  1099. second definition.
  1100.  
  1101.    In order for a redefinition to be trivial, the new definition must
  1102. exactly match the one already in effect, with two possible exceptions:
  1103.  
  1104.    * Whitespace may be added or deleted at the beginning or the end.
  1105.  
  1106.    * Whitespace may be changed in the middle (but not inside strings).
  1107.      However, it may not be eliminated entirely, and it may not be added
  1108.      where there was no whitespace at all.
  1109.  
  1110.    Recall that a comment counts as whitespace.
  1111.  
  1112. File: cpp.info,  Node: Macro Pitfalls,  Prev: Redefining,  Up: Macros
  1113.  
  1114. Pitfalls and Subtleties of Macros
  1115. ---------------------------------
  1116.  
  1117.    In this section we describe some special rules that apply to macros
  1118. and macro expansion, and point out certain cases in which the rules have
  1119. counterintuitive consequences that you must watch out for.
  1120.  
  1121. * Menu:
  1122.  
  1123. * Misnesting::        Macros can contain unmatched parentheses.
  1124. * Macro Parentheses:: Why apparently superfluous parentheses
  1125.                          may be necessary to avoid incorrect grouping.
  1126. * Swallow Semicolon:: Macros that look like functions
  1127.                          but expand into compound statements.
  1128. * Side Effects::      Unsafe macros that cause trouble when
  1129.                          arguments contain side effects.
  1130. * Self-Reference::    Macros whose definitions use the macros' own names.
  1131. * Argument Prescan::  Actual arguments are checked for macro calls
  1132.                          before they are substituted.
  1133. * Cascaded Macros::   Macros whose definitions use other macros.
  1134. * Newlines in Args::  Sometimes line numbers get confused.
  1135.  
  1136. File: cpp.info,  Node: Misnesting,  Next: Macro Parentheses,  Prev: Macro Pitfalls,  Up: Macro Pitfalls
  1137.  
  1138. Improperly Nested Constructs
  1139. ............................
  1140.  
  1141.    Recall that when a macro is called with arguments, the arguments are
  1142. substituted into the macro body and the result is checked, together with
  1143. the rest of the input file, for more macro calls.
  1144.  
  1145.    It is possible to piece together a macro call coming partially from
  1146. the macro body and partially from the actual arguments.  For example,
  1147.  
  1148.      #define double(x) (2*(x))
  1149.      #define call_with_1(x) x(1)
  1150.  
  1151. would expand `call_with_1 (double)' into `(2*(1))'.
  1152.  
  1153.    Macro definitions do not have to have balanced parentheses.  By
  1154. writing an unbalanced open parenthesis in a macro body, it is possible
  1155. to create a macro call that begins inside the macro body but ends
  1156. outside of it.  For example,
  1157.  
  1158.      #define strange(file) fprintf (file, "%s %d",
  1159.      ...
  1160.      strange(stderr) p, 35)
  1161.  
  1162. This bizarre example expands to `fprintf (stderr, "%s %d", p, 35)'!
  1163.  
  1164. File: cpp.info,  Node: Macro Parentheses,  Next: Swallow Semicolon,  Prev: Misnesting,  Up: Macro Pitfalls
  1165.  
  1166. Unintended Grouping of Arithmetic
  1167. .................................
  1168.  
  1169.    You may have noticed that in most of the macro definition examples
  1170. shown above, each occurrence of a macro argument name had parentheses
  1171. around it.  In addition, another pair of parentheses usually surround
  1172. the entire macro definition.  Here is why it is best to write macros
  1173. that way.
  1174.  
  1175.    Suppose you define a macro as follows,
  1176.  
  1177.      #define ceil_div(x, y) (x + y - 1) / y
  1178.  
  1179. whose purpose is to divide, rounding up.  (One use for this operation is
  1180. to compute how many `int' objects are needed to hold a certain number
  1181. of `char' objects.)  Then suppose it is used as follows:
  1182.  
  1183.      a = ceil_div (b & c, sizeof (int));
  1184.  
  1185. This expands into
  1186.  
  1187.      a = (b & c + sizeof (int) - 1) / sizeof (int);
  1188.  
  1189. which does not do what is intended.  The operator-precedence rules of C
  1190. make it equivalent to this:
  1191.  
  1192.      a = (b & (c + sizeof (int) - 1)) / sizeof (int);
  1193.  
  1194. But what we want is this:
  1195.  
  1196.      a = ((b & c) + sizeof (int) - 1)) / sizeof (int);
  1197.  
  1198. Defining the macro as
  1199.  
  1200.      #define ceil_div(x, y) ((x) + (y) - 1) / (y)
  1201.  
  1202. provides the desired result.
  1203.  
  1204.    However, unintended grouping can result in another way.  Consider
  1205. `sizeof ceil_div(1, 2)'.  That has the appearance of a C expression
  1206. that would compute the size of the type of `ceil_div (1, 2)', but in
  1207. fact it means something very different.  Here is what it expands to:
  1208.  
  1209.      sizeof ((1) + (2) - 1) / (2)
  1210.  
  1211. This would take the size of an integer and divide it by two.  The
  1212. precedence rules have put the division outside the `sizeof' when it was
  1213. intended to be inside.
  1214.  
  1215.    Parentheses around the entire macro definition can prevent such
  1216. problems.  Here, then, is the recommended way to define `ceil_div':
  1217.  
  1218.      #define ceil_div(x, y) (((x) + (y) - 1) / (y))
  1219.  
  1220. File: cpp.info,  Node: Swallow Semicolon,  Next: Side Effects,  Prev: Macro Parentheses,  Up: Macro Pitfalls
  1221.  
  1222. Swallowing the Semicolon
  1223. ........................
  1224.  
  1225.    Often it is desirable to define a macro that expands into a compound
  1226. statement.  Consider, for example, the following macro, that advances a
  1227. pointer (the argument `p' says where to find it) across whitespace
  1228. characters:
  1229.  
  1230.      #define SKIP_SPACES (p, limit)  \
  1231.      { register char *lim = (limit); \
  1232.        while (p != lim) {            \
  1233.          if (*p++ != ' ') {          \
  1234.            p--; break; }}}
  1235.  
  1236. Here Backslash-Newline is used to split the macro definition, which must
  1237. be a single line, so that it resembles the way such C code would be
  1238. laid out if not part of a macro definition.
  1239.  
  1240.    A call to this macro might be `SKIP_SPACES (p, lim)'.  Strictly
  1241. speaking, the call expands to a compound statement, which is a complete
  1242. statement with no need for a semicolon to end it.  But it looks like a
  1243. function call.  So it minimizes confusion if you can use it like a
  1244. function call, writing a semicolon afterward, as in `SKIP_SPACES (p,
  1245. lim);'
  1246.  
  1247.    But this can cause trouble before `else' statements, because the
  1248. semicolon is actually a null statement.  Suppose you write
  1249.  
  1250.      if (*p != 0)
  1251.        SKIP_SPACES (p, lim);
  1252.      else ...
  1253.  
  1254. The presence of two statements--the compound statement and a null
  1255. statement--in between the `if' condition and the `else' makes invalid C
  1256. code.
  1257.  
  1258.    The definition of the macro `SKIP_SPACES' can be altered to solve
  1259. this problem, using a `do ... while' statement.  Here is how:
  1260.  
  1261.      #define SKIP_SPACES (p, limit)     \
  1262.      do { register char *lim = (limit); \
  1263.           while (p != lim) {            \
  1264.             if (*p++ != ' ') {          \
  1265.               p--; break; }}}           \
  1266.      while (0)
  1267.  
  1268.    Now `SKIP_SPACES (p, lim);' expands into
  1269.  
  1270.      do {...} while (0);
  1271.  
  1272. which is one statement.
  1273.  
  1274. File: cpp.info,  Node: Side Effects,  Next: Self-Reference,  Prev: Swallow Semicolon,  Up: Macro Pitfalls
  1275.  
  1276. Duplication of Side Effects
  1277. ...........................
  1278.  
  1279.    Many C programs define a macro `min', for "minimum", like this:
  1280.  
  1281.      #define min(X, Y)  ((X) < (Y) ? (X) : (Y))
  1282.  
  1283.    When you use this macro with an argument containing a side effect,
  1284. as shown here,
  1285.  
  1286.      next = min (x + y, foo (z));
  1287.  
  1288. it expands as follows:
  1289.  
  1290.      next = ((x + y) < (foo (z)) ? (x + y) : (foo (z)));
  1291.  
  1292. where `x + y' has been substituted for `X' and `foo (z)' for `Y'.
  1293.  
  1294.    The function `foo' is used only once in the statement as it appears
  1295. in the program, but the expression `foo (z)' has been substituted twice
  1296. into the macro expansion.  As a result, `foo' might be called two times
  1297. when the statement is executed.  If it has side effects or if it takes
  1298. a long time to compute, the results might not be what you intended.  We
  1299. say that `min' is an "unsafe" macro.
  1300.  
  1301.    The best solution to this problem is to define `min' in a way that
  1302. computes the value of `foo (z)' only once.  The C language offers no
  1303. standard way to do this, but it can be done with GNU C extensions as
  1304. follows:
  1305.  
  1306.      #define min(X, Y)                     \
  1307.      ({ typeof (X) __x = (X), __y = (Y);   \
  1308.         (__x < __y) ? __x : __y; })
  1309.  
  1310.    If you do not wish to use GNU C extensions, the only solution is to
  1311. be careful when *using* the macro `min'.  For example, you can
  1312. calculate the value of `foo (z)', save it in a variable, and use that
  1313. variable in `min':
  1314.  
  1315.      #define min(X, Y)  ((X) < (Y) ? (X) : (Y))
  1316.      ...
  1317.      {
  1318.        int tem = foo (z);
  1319.        next = min (x + y, tem);
  1320.      }
  1321.  
  1322. (where we assume that `foo' returns type `int').
  1323.  
  1324. File: cpp.info,  Node: Self-Reference,  Next: Argument Prescan,  Prev: Side Effects,  Up: Macro Pitfalls
  1325.  
  1326. Self-Referential Macros
  1327. .......................
  1328.  
  1329.    A "self-referential" macro is one whose name appears in its
  1330. definition.  A special feature of ANSI Standard C is that the
  1331. self-reference is not considered a macro call.  It is passed into the
  1332. preprocessor output unchanged.
  1333.  
  1334.    Let's consider an example:
  1335.  
  1336.      #define foo (4 + foo)
  1337.  
  1338. where `foo' is also a variable in your program.
  1339.  
  1340.    Following the ordinary rules, each reference to `foo' will expand
  1341. into `(4 + foo)'; then this will be rescanned and will expand into `(4
  1342. + (4 + foo))'; and so on until it causes a fatal error (memory full) in
  1343. the preprocessor.
  1344.  
  1345.    However, the special rule about self-reference cuts this process
  1346. short after one step, at `(4 + foo)'.  Therefore, this macro definition
  1347. has the possibly useful effect of causing the program to add 4 to the
  1348. value of `foo' wherever `foo' is referred to.
  1349.  
  1350.    In most cases, it is a bad idea to take advantage of this feature.  A
  1351. person reading the program who sees that `foo' is a variable will not
  1352. expect that it is a macro as well.  The reader will come across the
  1353. identifier `foo' in the program and think its value should be that of
  1354. the variable `foo', whereas in fact the value is four greater.
  1355.  
  1356.    The special rule for self-reference applies also to "indirect"
  1357. self-reference.  This is the case where a macro X expands to use a
  1358. macro `y', and the expansion of `y' refers to the macro `x'.  The
  1359. resulting reference to `x' comes indirectly from the expansion of `x',
  1360. so it is a self-reference and is not further expanded.  Thus, after
  1361.  
  1362.      #define x (4 + y)
  1363.      #define y (2 * x)
  1364.  
  1365. `x' would expand into `(4 + (2 * x))'.  Clear?
  1366.  
  1367.    But suppose `y' is used elsewhere, not from the definition of `x'.
  1368. Then the use of `x' in the expansion of `y' is not a self-reference
  1369. because `x' is not "in progress".  So it does expand.  However, the
  1370. expansion of `x' contains a reference to `y', and that is an indirect
  1371. self-reference now because `y' is "in progress".  The result is that
  1372. `y' expands to `(2 * (4 + y))'.
  1373.  
  1374.    It is not clear that this behavior would ever be useful, but it is
  1375. specified by the ANSI C standard, so you may need to understand it.
  1376.  
  1377. File: cpp.info,  Node: Argument Prescan,  Next: Cascaded Macros,  Prev: Self-Reference,  Up: Macro Pitfalls
  1378.  
  1379. Separate Expansion of Macro Arguments
  1380. .....................................
  1381.  
  1382.    We have explained that the expansion of a macro, including the
  1383. substituted actual arguments, is scanned over again for macro calls to
  1384. be expanded.
  1385.  
  1386.    What really happens is more subtle: first each actual argument text
  1387. is scanned separately for macro calls.  Then the results of this are
  1388. substituted into the macro body to produce the macro expansion, and the
  1389. macro expansion is scanned again for macros to expand.
  1390.  
  1391.    The result is that the actual arguments are scanned *twice* to expand
  1392. macro calls in them.
  1393.  
  1394.    Most of the time, this has no effect.  If the actual argument
  1395. contained any macro calls, they are expanded during the first scan.
  1396. The result therefore contains no macro calls, so the second scan does
  1397. not change it.  If the actual argument were substituted as given, with
  1398. no prescan, the single remaining scan would find the same macro calls
  1399. and produce the same results.
  1400.  
  1401.    You might expect the double scan to change the results when a
  1402. self-referential macro is used in an actual argument of another macro
  1403. (*note Self-Reference::.): the self-referential macro would be expanded
  1404. once in the first scan, and a second time in the second scan.  But this
  1405. is not what happens.  The self-references that do not expand in the
  1406. first scan are marked so that they will not expand in the second scan
  1407. either.
  1408.  
  1409.    The prescan is not done when an argument is stringified or
  1410. concatenated.  Thus,
  1411.  
  1412.      #define str(s) #s
  1413.      #define foo 4
  1414.      str (foo)
  1415.  
  1416. expands to `"foo"'.  Once more, prescan has been prevented from having
  1417. any noticeable effect.
  1418.  
  1419.    More precisely, stringification and concatenation use the argument as
  1420. written, in un-prescanned form.  The same actual argument would be used
  1421. in prescanned form if it is substituted elsewhere without
  1422. stringification or concatenation.
  1423.  
  1424.      #define str(s) #s lose(s)
  1425.      #define foo 4
  1426.      str (foo)
  1427.  
  1428.    expands to `"foo" lose(4)'.
  1429.  
  1430.    You might now ask, "Why mention the prescan, if it makes no
  1431. difference?  And why not skip it and make the preprocessor faster?"
  1432. The answer is that the prescan does make a difference in three special
  1433. cases:
  1434.  
  1435.    * Nested calls to a macro.
  1436.  
  1437.    * Macros that call other macros that stringify or concatenate.
  1438.  
  1439.    * Macros whose expansions contain unshielded commas.
  1440.  
  1441.    We say that "nested" calls to a macro occur when a macro's actual
  1442. argument contains a call to that very macro.  For example, if `f' is a
  1443. macro that expects one argument, `f (f (1))' is a nested pair of calls
  1444. to `f'.  The desired expansion is made by expanding `f (1)' and
  1445. substituting that into the definition of `f'.  The prescan causes the
  1446. expected result to happen.  Without the prescan, `f (1)' itself would
  1447. be substituted as an actual argument, and the inner use of `f' would
  1448. appear during the main scan as an indirect self-reference and would not
  1449. be expanded.  Here, the prescan cancels an undesirable side effect (in
  1450. the medical, not computational, sense of the term) of the special rule
  1451. for self-referential macros.
  1452.  
  1453.    But prescan causes trouble in certain other cases of nested macro
  1454. calls.  Here is an example:
  1455.  
  1456.      #define foo  a,b
  1457.      #define bar(x) lose(x)
  1458.      #define lose(x) (1 + (x))
  1459.      
  1460.      bar(foo)
  1461.  
  1462. We would like `bar(foo)' to turn into `(1 + (foo))', which would then
  1463. turn into `(1 + (a,b))'.  But instead, `bar(foo)' expands into
  1464. `lose(a,b)', and you get an error because `lose' requires a single
  1465. argument.  In this case, the problem is easily solved by the same
  1466. parentheses that ought to be used to prevent misnesting of arithmetic
  1467. operations:
  1468.  
  1469.      #define foo (a,b)
  1470.      #define bar(x) lose((x))
  1471.  
  1472.    The problem is more serious when the operands of the macro are not
  1473. expressions; for example, when they are statements.  Then parentheses
  1474. are unacceptable because they would make for invalid C code:
  1475.  
  1476.      #define foo { int a, b; ... }
  1477.  
  1478. In GNU C you can shield the commas using the `({...})' construct which
  1479. turns a compound statement into an expression:
  1480.  
  1481.      #define foo ({ int a, b; ... })
  1482.  
  1483.    Or you can rewrite the macro definition to avoid such commas:
  1484.  
  1485.      #define foo { int a; int b; ... }
  1486.  
  1487.    There is also one case where prescan is useful.  It is possible to
  1488. use prescan to expand an argument and then stringify it--if you use two
  1489. levels of macros.  Let's add a new macro `xstr' to the example shown
  1490. above:
  1491.  
  1492.      #define xstr(s) str(s)
  1493.      #define str(s) #s
  1494.      #define foo 4
  1495.      xstr (foo)
  1496.  
  1497.    This expands into `"4"', not `"foo"'.  The reason for the difference
  1498. is that the argument of `xstr' is expanded at prescan (because `xstr'
  1499. does not specify stringification or concatenation of the argument).
  1500. The result of prescan then forms the actual argument for `str'.  `str'
  1501. uses its argument without prescan because it performs stringification;
  1502. but it cannot prevent or undo the prescanning already done by `xstr'.
  1503.  
  1504. File: cpp.info,  Node: Cascaded Macros,  Next: Newlines in Args,  Prev: Argument Prescan,  Up: Macro Pitfalls
  1505.  
  1506. Cascaded Use of Macros
  1507. ......................
  1508.  
  1509.    A "cascade" of macros is when one macro's body contains a reference
  1510. to another macro.  This is very common practice.  For example,
  1511.  
  1512.      #define BUFSIZE 1020
  1513.      #define TABLESIZE BUFSIZE
  1514.  
  1515.    This is not at all the same as defining `TABLESIZE' to be `1020'.
  1516. The `#define' for `TABLESIZE' uses exactly the body you specify--in
  1517. this case, `BUFSIZE'--and does not check to see whether it too is the
  1518. name of a macro.
  1519.  
  1520.    It's only when you *use* `TABLESIZE' that the result of its expansion
  1521. is checked for more macro names.
  1522.  
  1523.    This makes a difference if you change the definition of `BUFSIZE' at
  1524. some point in the source file.  `TABLESIZE', defined as shown, will
  1525. always expand using the definition of `BUFSIZE' that is currently in
  1526. effect:
  1527.  
  1528.      #define BUFSIZE 1020
  1529.      #define TABLESIZE BUFSIZE
  1530.      #undef BUFSIZE
  1531.      #define BUFSIZE 37
  1532.  
  1533. Now `TABLESIZE' expands (in two stages) to `37'.  (The `#undef' is to
  1534. prevent any warning about the nontrivial redefinition of `BUFSIZE'.)
  1535.  
  1536. File: cpp.info,  Node: Newlines in Args,  Prev: Cascaded Macros,  Up: Macro Pitfalls
  1537.  
  1538. Newlines in Macro Arguments
  1539. ---------------------------
  1540.  
  1541.    Traditional macro processing carries forward all newlines in macro
  1542. arguments into the expansion of the macro.  This means that, if some of
  1543. the arguments are substituted more than once, or not at all, or out of
  1544. order, newlines can be duplicated, lost, or moved around within the
  1545. expansion.  If the expansion consists of multiple statements, then the
  1546. effect is to distort the line numbers of some of these statements.  The
  1547. result can be incorrect line numbers, in error messages or displayed in
  1548. a debugger.
  1549.  
  1550.    The GNU C preprocessor operating in ANSI C mode adjusts appropriately
  1551. for multiple use of an argument--the first use expands all the
  1552. newlines, and subsequent uses of the same argument produce no newlines.
  1553. But even in this mode, it can produce incorrect line numbering if
  1554. arguments are used out of order, or not used at all.
  1555.  
  1556.    Here is an example illustrating this problem:
  1557.  
  1558.      #define ignore_second_arg(a,b,c) a; c
  1559.      
  1560.      ignore_second_arg (foo (),
  1561.                         ignored (),
  1562.                         syntax error);
  1563.  
  1564. The syntax error triggered by the tokens `syntax error' results in an
  1565. error message citing line four, even though the statement text comes
  1566. from line five.
  1567.  
  1568. File: cpp.info,  Node: Conditionals,  Next: Combining Sources,  Prev: Macros,  Up: Top
  1569.  
  1570. Conditionals
  1571. ============
  1572.  
  1573.    In a macro processor, a "conditional" is a command that allows a part
  1574. of the program to be ignored during compilation, on some conditions.
  1575. In the C preprocessor, a conditional can test either an arithmetic
  1576. expression or whether a name is defined as a macro.
  1577.  
  1578.    A conditional in the C preprocessor resembles in some ways an `if'
  1579. statement in C, but it is important to understand the difference between
  1580. them.  The condition in an `if' statement is tested during the execution
  1581. of your program.  Its purpose is to allow your program to behave
  1582. differently from run to run, depending on the data it is operating on.
  1583. The condition in a preprocessor conditional command is tested when your
  1584. program is compiled.  Its purpose is to allow different code to be
  1585. included in the program depending on the situation at the time of
  1586. compilation.
  1587.  
  1588. * Menu:
  1589.  
  1590. * Uses: Conditional Uses.       What conditionals are for.
  1591. * Syntax: Conditional Syntax.   How conditionals are written.
  1592. * Deletion: Deleted Code.       Making code into a comment.
  1593. * Macros: Conditionals-Macros.  Why conditionals are used with macros.
  1594. * Assertions::                How and why to use assertions.
  1595. * Errors: #error Command.       Detecting inconsistent compilation parameters.
  1596.  
  1597. File: cpp.info,  Node: Conditional Uses,  Next: Conditional Syntax,  Up: Conditionals
  1598.  
  1599. Why Conditionals are Used
  1600. -------------------------
  1601.  
  1602.    Generally there are three kinds of reason to use a conditional.
  1603.  
  1604.    * A program may need to use different code depending on the machine
  1605.      or operating system it is to run on.  In some cases the code for
  1606.      one operating system may be erroneous on another operating system;
  1607.      for example, it might refer to library routines that do not exist
  1608.      on the other system.  When this happens, it is not enough to avoid
  1609.      executing the invalid code: merely having it in the program makes
  1610.      it impossible to link the program and run it.  With a preprocessor
  1611.      conditional, the offending code can be effectively excised from
  1612.      the program when it is not valid.
  1613.  
  1614.    * You may want to be able to compile the same source file into two
  1615.      different programs.  Sometimes the difference between the programs
  1616.      is that one makes frequent time-consuming consistency checks on its
  1617.      intermediate data, or prints the values of those data for
  1618.      debugging, while the other does not.
  1619.  
  1620.    * A conditional whose condition is always false is a good way to
  1621.      exclude code from the program but keep it as a sort of comment for
  1622.      future reference.
  1623.  
  1624.    Most simple programs that are intended to run on only one machine
  1625. will not need to use preprocessor conditionals.
  1626.  
  1627. File: cpp.info,  Node: Conditional Syntax,  Next: Deleted Code,  Prev: Conditional Uses,  Up: Conditionals
  1628.  
  1629. Syntax of Conditionals
  1630. ----------------------
  1631.  
  1632.    A conditional in the C preprocessor begins with a "conditional
  1633. command": `#if', `#ifdef' or `#ifndef'.  *Note Conditionals-Macros::,
  1634. for information on `#ifdef' and `#ifndef'; only `#if' is explained here.
  1635.  
  1636. * Menu:
  1637.  
  1638. * If: #if Command.     Basic conditionals using `#if' and `#endif'.
  1639. * Else: #else Command. Including some text if the condition fails.
  1640. * Elif: #elif Command. Testing several alternative possibilities.
  1641.  
  1642. File: cpp.info,  Node: #if Command,  Next: #else Command,  Up: Conditional Syntax
  1643.  
  1644. The `#if' Command
  1645. .................
  1646.  
  1647.    The `#if' command in its simplest form consists of
  1648.  
  1649.      #if EXPRESSION
  1650.      CONTROLLED TEXT
  1651.      #endif /* EXPRESSION */
  1652.  
  1653.    The comment following the `#endif' is not required, but it is a good
  1654. practice because it helps people match the `#endif' to the
  1655. corresponding `#if'.  Such comments should always be used, except in
  1656. short conditionals that are not nested.  In fact, you can put anything
  1657. at all after the `#endif' and it will be ignored by the GNU C
  1658. preprocessor, but only comments are acceptable in ANSI Standard C.
  1659.  
  1660.    EXPRESSION is a C expression of integer type, subject to stringent
  1661. restrictions.  It may contain
  1662.  
  1663.    * Integer constants, which are all regarded as `long' or `unsigned
  1664.      long'.
  1665.  
  1666.    * Character constants, which are interpreted according to the
  1667.      character set and conventions of the machine and operating system
  1668.      on which the preprocessor is running.  The GNU C preprocessor uses
  1669.      the C data type `char' for these character constants; therefore,
  1670.      whether some character codes are negative is determined by the C
  1671.      compiler used to compile the preprocessor.  If it treats `char' as
  1672.      signed, then character codes large enough to set the sign bit will
  1673.      be considered negative; otherwise, no character code is considered
  1674.      negative.
  1675.  
  1676.    * Arithmetic operators for addition, subtraction, multiplication,
  1677.      division, bitwise operations, shifts, comparisons, and logical
  1678.      operations (`&&' and `||').
  1679.  
  1680.    * Identifiers that are not macros, which are all treated as zero(!).
  1681.  
  1682.    * Macro calls.  All macro calls in the expression are expanded before
  1683.      actual computation of the expression's value begins.
  1684.  
  1685.    Note that `sizeof' operators and `enum'-type values are not allowed.
  1686. `enum'-type values, like all other identifiers that are not taken as
  1687. macro calls and expanded, are treated as zero.
  1688.  
  1689.    The CONTROLLED TEXT inside of a conditional can include preprocessor
  1690. commands.  Then the commands inside the conditional are obeyed only if
  1691. that branch of the conditional succeeds.  The text can also contain
  1692. other conditional groups.  However, the `#if' and `#endif' commands
  1693. must balance.
  1694.  
  1695. File: cpp.info,  Node: #else Command,  Next: #elif Command,  Prev: #if Command,  Up: Conditional Syntax
  1696.  
  1697. The `#else' Command
  1698. ...................
  1699.  
  1700.    The `#else' command can be added to a conditional to provide
  1701. alternative text to be used if the condition is false.  This is what it
  1702. looks like:
  1703.  
  1704.      #if EXPRESSION
  1705.      TEXT-IF-TRUE
  1706.      #else /* Not EXPRESSION */
  1707.      TEXT-IF-FALSE
  1708.      #endif /* Not EXPRESSION */
  1709.  
  1710.    If EXPRESSION is nonzero, and thus the TEXT-IF-TRUE is active, then
  1711. `#else' acts like a failing conditional and the TEXT-IF-FALSE is
  1712. ignored.  Contrariwise, if the `#if' conditional fails, the
  1713. TEXT-IF-FALSE is considered included.
  1714.  
  1715. File: cpp.info,  Node: #elif Command,  Prev: #else Command,  Up: Conditional Syntax
  1716.  
  1717. The `#elif' Command
  1718. ...................
  1719.  
  1720.    One common case of nested conditionals is used to check for more
  1721. than two possible alternatives.  For example, you might have
  1722.  
  1723.      #if X == 1
  1724.      ...
  1725.      #else /* X != 1 */
  1726.      #if X == 2
  1727.      ...
  1728.      #else /* X != 2 */
  1729.      ...
  1730.      #endif /* X != 2 */
  1731.      #endif /* X != 1 */
  1732.  
  1733.    Another conditional command, `#elif', allows this to be abbreviated
  1734. as follows:
  1735.  
  1736.      #if X == 1
  1737.      ...
  1738.      #elif X == 2
  1739.      ...
  1740.      #else /* X != 2 and X != 1*/
  1741.      ...
  1742.      #endif /* X != 2 and X != 1*/
  1743.  
  1744.    `#elif' stands for "else if".  Like `#else', it goes in the middle
  1745. of a `#if'-`#endif' pair and subdivides it; it does not require a
  1746. matching `#endif' of its own.  Like `#if', the `#elif' command includes
  1747. an expression to be tested.
  1748.  
  1749.    The text following the `#elif' is processed only if the original
  1750. `#if'-condition failed and the `#elif' condition succeeds.  More than
  1751. one `#elif' can go in the same `#if'-`#endif' group.  Then the text
  1752. after each `#elif' is processed only if the `#elif' condition succeeds
  1753. after the original `#if' and any previous `#elif' commands within it
  1754. have failed.  `#else' is equivalent to `#elif 1', and `#else' is
  1755. allowed after any number of `#elif' commands, but `#elif' may not follow
  1756. `#else'.
  1757.  
  1758. File: cpp.info,  Node: Deleted Code,  Next: Conditionals-Macros,  Prev: Conditional Syntax,  Up: Conditionals
  1759.  
  1760. Keeping Deleted Code for Future Reference
  1761. -----------------------------------------
  1762.  
  1763.    If you replace or delete a part of the program but want to keep the
  1764. old code around as a comment for future reference, the easy way to do
  1765. this is to put `#if 0' before it and `#endif' after it.  This is better
  1766. than using comment delimiters `/*' and `*/' since those won't work if
  1767. the code already contains comments (C comments do not nest).
  1768.  
  1769.    This works even if the code being turned off contains conditionals,
  1770. but they must be entire conditionals (balanced `#if' and `#endif').
  1771.  
  1772.    Conversely, do not use `#if 0' for comments which are not C code.
  1773. Use the comment delimiters `/*' and `*/' instead.  The interior of `#if
  1774. 0' must consist of complete tokens; in particular, singlequote
  1775. characters must balance.  But comments often contain unbalanced
  1776. singlequote characters (known in English as apostrophes).  These
  1777. confuse `#if 0'.  They do not confuse `/*'.
  1778.  
  1779. File: cpp.info,  Node: Conditionals-Macros,  Next: Assertions,  Prev: Deleted Code,  Up: Conditionals
  1780.  
  1781. Conditionals and Macros
  1782. -----------------------
  1783.  
  1784.    Conditionals are useful in connection with macros or assertions,
  1785. because those are the only ways that an expression's value can vary
  1786. from one compilation to another.  A `#if' command whose expression uses
  1787. no macros or assertions is equivalent to `#if 1' or `#if 0'; you might
  1788. as well determine which one, by computing the value of the expression
  1789. yourself, and then simplify the program.
  1790.  
  1791.    For example, here is a conditional that tests the expression
  1792. `BUFSIZE == 1020', where `BUFSIZE' must be a macro.
  1793.  
  1794.      #if BUFSIZE == 1020
  1795.        printf ("Large buffers!\n");
  1796.      #endif /* BUFSIZE is large */
  1797.  
  1798.    (Programmers often wish they could test the size of a variable or
  1799. data type in `#if', but this does not work.  The preprocessor does not
  1800. understand `sizeof', or typedef names, or even the type keywords such
  1801. as `int'.)
  1802.  
  1803.    The special operator `defined' is used in `#if' expressions to test
  1804. whether a certain name is defined as a macro.  Either `defined NAME' or
  1805. `defined (NAME)' is an expression whose value is 1 if NAME is defined
  1806. as macro at the current point in the program, and 0 otherwise.  For the
  1807. `defined' operator it makes no difference what the definition of the
  1808. macro is; all that matters is whether there is a definition.  Thus, for
  1809. example,
  1810.  
  1811.      #if defined (vax) || defined (ns16000)
  1812.  
  1813. would succeed if either of the names `vax' and `ns16000' is defined as
  1814. a macro.  You can test the same condition using assertions (*note
  1815. Assertions::.), like this:
  1816.  
  1817.      #if #cpu (vax) || #cpu (ns16000)
  1818.  
  1819.    If a macro is defined and later undefined with `#undef', subsequent
  1820. use of the `defined' operator returns 0, because the name is no longer
  1821. defined.  If the macro is defined again with another `#define',
  1822. `defined' will recommence returning 1.
  1823.  
  1824.    Conditionals that test whether just one name is defined are very
  1825. common, so there are two special short conditional commands for this
  1826. case.
  1827.  
  1828. `#ifdef NAME'
  1829.      is equivalent to `#if defined (NAME)'.
  1830.  
  1831. `#ifndef NAME'
  1832.      is equivalent to `#if ! defined (NAME)'.
  1833.  
  1834.    Macro definitions can vary between compilations for several reasons.
  1835.  
  1836.    * Some macros are predefined on each kind of machine.  For example,
  1837.      on a Vax, the name `vax' is a predefined macro.  On other
  1838.      machines, it would not be defined.
  1839.  
  1840.    * Many more macros are defined by system header files.  Different
  1841.      systems and machines define different macros, or give them
  1842.      different values.  It is useful to test these macros with
  1843.      conditionals to avoid using a system feature on a machine where it
  1844.      is not implemented.
  1845.  
  1846.    * Macros are a common way of allowing users to customize a program
  1847.      for different machines or applications.  For example, the macro
  1848.      `BUFSIZE' might be defined in a configuration file for your
  1849.      program that is included as a header file in each source file.  You
  1850.      would use `BUFSIZE' in a preprocessor conditional in order to
  1851.      generate different code depending on the chosen configuration.
  1852.  
  1853.    * Macros can be defined or undefined with `-D' and `-U' command
  1854.      options when you compile the program.  You can arrange to compile
  1855.      the same source file into two different programs by choosing a
  1856.      macro name to specify which program you want, writing conditionals
  1857.      to test whether or how this macro is defined, and then controlling
  1858.      the state of the macro with compiler command options.  *Note
  1859.      Invocation::.
  1860.  
  1861.    Assertions are usually predefined, but can be defined with
  1862. preprocessor commands or command-line options.
  1863.  
  1864. File: cpp.info,  Node: Assertions,  Next: #error Command,  Prev: Conditionals-Macros,  Up: Conditionals
  1865.  
  1866. Assertions
  1867. ----------
  1868.  
  1869.    "Assertions" are a more systematic alternative to macros in writing
  1870. conditionals to test what sort of computer or system the compiled
  1871. program will run on.  Assertions are usually predefined, but you can
  1872. define them with preprocessor commands or command-line options.
  1873.  
  1874.    The macros traditionally used to describe the type of target are not
  1875. classified in any way according to which question they answer; they may
  1876. indicate a hardware architecture, a particular hardware model, an
  1877. operating system, a particular version of an operating system, or
  1878. specific configuration options.  These are jumbled together in a single
  1879. namespace.  In contrast, each assertion consists of a named question and
  1880. an answer.  The question is usually called the "predicate".  An
  1881. assertion looks like this:
  1882.  
  1883.      #PREDICATE (ANSWER)
  1884.  
  1885. You must use a properly formed identifier for PREDICATE.  The value of
  1886. ANSWER can be any sequence of words; all characters are significant
  1887. except for leading and trailing whitespace, and differences in internal
  1888. whitespace sequences are ignored.  Thus, `x + y' is different from
  1889. `x+y' but equivalent to `x + y'.  `)' is not allowed in an answer.
  1890.  
  1891.    Here is a conditional to test whether the answer ANSWER is asserted
  1892. for the predicate PREDICATE:
  1893.  
  1894.      #if #PREDICATE (ANSWER)
  1895.  
  1896. There may be more than one answer asserted for a given predicate.  If
  1897. you omit the answer, you can test whether *any* answer is asserted for
  1898. PREDICATE:
  1899.  
  1900.      #if #PREDICATE
  1901.  
  1902.    Most of the time, the assertions you test will be predefined
  1903. assertions.  GNU C provides three predefined predicates: `system',
  1904. `cpu', and `machine'.  `system' is for assertions about the type of
  1905. software, `cpu' describes the type of computer architecture, and
  1906. `machine' gives more information about the computer.  For example, on a
  1907. GNU system, the following assertions would be true:
  1908.  
  1909.      #system (gnu)
  1910.      #system (mach)
  1911.      #system (mach 3)
  1912.      #system (mach 3.SUBVERSION)
  1913.      #system (hurd)
  1914.      #system (hurd VERSION)
  1915.  
  1916. and perhaps others.  The alternatives with more or less version
  1917. information let you ask more or less detailed questions about the type
  1918. of system software.
  1919.  
  1920.    On a Unix system, you would find `#system (unix)' and perhaps one of:
  1921. `#system (aix)', `#system (bsd)', `#system (hpux)', `#system (lynx)',
  1922. `#system (mach)', `#system (posix)', `#system (svr3)', `#system
  1923. (svr4)', or `#system (xpg4)' with possible version numbers following.
  1924.  
  1925.    Other values for `system' are `#system (mvs)' and `#system (vms)'.
  1926.  
  1927.    *Portability note:* Many Unix C compilers provide only one answer
  1928. for the `system' assertion: `#system (unix)', if they support
  1929. assertions at all.  This is less than useful.
  1930.  
  1931.    An assertion with a multi-word answer is completely different from
  1932. several assertions with individual single-word answers.  For example,
  1933. the presence of `system (mach 3.0)' does not mean that `system (3.0)'
  1934. is true.  It also does not directly imply `system (mach)', but in GNU
  1935. C, that last will normally be asserted as well.
  1936.  
  1937.    The current list of possible assertion values for `cpu' is: `#cpu
  1938. (a29k)', `#cpu (alpha)', `#cpu (arm)', `#cpu (clipper)', `#cpu
  1939. (convex)', `#cpu (elxsi)', `#cpu (tron)', `#cpu (h8300)', `#cpu
  1940. (i370)', `#cpu (i386)', `#cpu (i860)', `#cpu (i960)', `#cpu (m68k)',
  1941. `#cpu (m88k)', `#cpu (mips)', `#cpu (ns32k)', `#cpu (hppa)', `#cpu
  1942. (pyr)', `#cpu (ibm032)', `#cpu (rs6000)', `#cpu (sh)', `#cpu (sparc)',
  1943. `#cpu (spur)', `#cpu (tahoe)', `#cpu (vax)', `#cpu (we32000)'.
  1944.  
  1945.    You can create assertions within a C program using `#assert', like
  1946. this:
  1947.  
  1948.      #assert PREDICATE (ANSWER)
  1949.  
  1950. (Note the absence of a `#' before PREDICATE.)
  1951.  
  1952.    Each time you do this, you assert a new true answer for PREDICATE.
  1953. Asserting one answer does not invalidate previously asserted answers;
  1954. they all remain true.  The only way to remove an assertion is with
  1955. `#unassert'.  `#unassert' has the same syntax as `#assert'.  You can
  1956. also remove all assertions about PREDICATE like this:
  1957.  
  1958.      #unassert PREDICATE
  1959.  
  1960.    You can also add or cancel assertions using command options when you
  1961. run `gcc' or `cpp'.  *Note Invocation::.
  1962.  
  1963. File: cpp.info,  Node: #error Command,  Prev: Assertions,  Up: Conditionals
  1964.  
  1965. The `#error' and `#warning' Commands
  1966. ------------------------------------
  1967.  
  1968.    The command `#error' causes the preprocessor to report a fatal
  1969. error.  The rest of the line that follows `#error' is used as the error
  1970. message.
  1971.  
  1972.    You would use `#error' inside of a conditional that detects a
  1973. combination of parameters which you know the program does not properly
  1974. support.  For example, if you know that the program will not run
  1975. properly on a Vax, you might write
  1976.  
  1977.      #ifdef __vax__
  1978.      #error Won't work on Vaxen.  See comments at get_last_object.
  1979.      #endif
  1980.  
  1981. *Note Nonstandard Predefined::, for why this works.
  1982.  
  1983.    If you have several configuration parameters that must be set up by
  1984. the installation in a consistent way, you can use conditionals to detect
  1985. an inconsistency and report it with `#error'.  For example,
  1986.  
  1987.      #if HASH_TABLE_SIZE % 2 == 0 || HASH_TABLE_SIZE % 3 == 0 \
  1988.          || HASH_TABLE_SIZE % 5 == 0
  1989.      #error HASH_TABLE_SIZE should not be divisible by a small prime
  1990.      #endif
  1991.  
  1992.    The command `#warning' is like the command `#error', but causes the
  1993. preprocessor to issue a warning and continue preprocessing.  The rest of
  1994. the line that follows `#warning' is used as the warning message.
  1995.  
  1996.    You might use `#warning' in obsolete header files, with a message
  1997. directing the user to the header file which should be used instead.
  1998.  
  1999. File: cpp.info,  Node: Combining Sources,  Next: Other Commands,  Prev: Conditionals,  Up: Top
  2000.  
  2001. Combining Source Files
  2002. ======================
  2003.  
  2004.    One of the jobs of the C preprocessor is to inform the C compiler of
  2005. where each line of C code came from: which source file and which line
  2006. number.
  2007.  
  2008.    C code can come from multiple source files if you use `#include';
  2009. both `#include' and the use of conditionals and macros can cause the
  2010. line number of a line in the preprocessor output to be different from
  2011. the line's number in the original source file.  You will appreciate the
  2012. value of making both the C compiler (in error messages) and symbolic
  2013. debuggers such as GDB use the line numbers in your source file.
  2014.  
  2015.    The C preprocessor builds on this feature by offering a command by
  2016. which you can control the feature explicitly.  This is useful when a
  2017. file for input to the C preprocessor is the output from another program
  2018. such as the `bison' parser generator, which operates on another file
  2019. that is the true source file.  Parts of the output from `bison' are
  2020. generated from scratch, other parts come from a standard parser file.
  2021. The rest are copied nearly verbatim from the source file, but their
  2022. line numbers in the `bison' output are not the same as their original
  2023. line numbers.  Naturally you would like compiler error messages and
  2024. symbolic debuggers to know the original source file and line number of
  2025. each line in the `bison' input.
  2026.  
  2027.    `bison' arranges this by writing `#line' commands into the output
  2028. file.  `#line' is a command that specifies the original line number and
  2029. source file name for subsequent input in the current preprocessor input
  2030. file.  `#line' has three variants:
  2031.  
  2032. `#line LINENUM'
  2033.      Here LINENUM is a decimal integer constant.  This specifies that
  2034.      the line number of the following line of input, in its original
  2035.      source file, was LINENUM.
  2036.  
  2037. `#line LINENUM FILENAME'
  2038.      Here LINENUM is a decimal integer constant and FILENAME is a
  2039.      string constant.  This specifies that the following line of input
  2040.      came originally from source file FILENAME and its line number there
  2041.      was LINENUM.  Keep in mind that FILENAME is not just a file name;
  2042.      it is surrounded by doublequote characters so that it looks like a
  2043.      string constant.
  2044.  
  2045. `#line ANYTHING ELSE'
  2046.      ANYTHING ELSE is checked for macro calls, which are expanded.  The
  2047.      result should be a decimal integer constant followed optionally by
  2048.      a string constant, as described above.
  2049.  
  2050.    `#line' commands alter the results of the `__FILE__' and `__LINE__'
  2051. predefined macros from that point on.  *Note Standard Predefined::.
  2052.  
  2053.    The output of the preprocessor (which is the input for the rest of
  2054. the compiler) contains commands that look much like `#line' commands.
  2055. They start with just `#' instead of `#line', but this is followed by a
  2056. line number and file name as in `#line'.  *Note Output::.
  2057.  
  2058. File: cpp.info,  Node: Other Commands,  Next: Output,  Prev: Combining Sources,  Up: Top
  2059.  
  2060. Miscellaneous Preprocessor Commands
  2061. ===================================
  2062.  
  2063.    This section describes three additional preprocessor commands.  They
  2064. are not very useful, but are mentioned for completeness.
  2065.  
  2066.    The "null command" consists of a `#' followed by a Newline, with
  2067. only whitespace (including comments) in between.  A null command is
  2068. understood as a preprocessor command but has no effect on the
  2069. preprocessor output.  The primary significance of the existence of the
  2070. null command is that an input line consisting of just a `#' will
  2071. produce no output, rather than a line of output containing just a `#'.
  2072. Supposedly some old C programs contain such lines.
  2073.  
  2074.    The ANSI standard specifies that the `#pragma' command has an
  2075. arbitrary, implementation-defined effect.  In the GNU C preprocessor,
  2076. `#pragma' commands are not used, except for `#pragma once' (*note
  2077. Once-Only::.).  However, they are left in the preprocessor output, so
  2078. they are available to the compilation pass.
  2079.  
  2080.    The `#ident' command is supported for compatibility with certain
  2081. other systems.  It is followed by a line of text.  On some systems, the
  2082. text is copied into a special place in the object file; on most systems,
  2083. the text is ignored and this command has no effect.  Typically `#ident'
  2084. is only used in header files supplied with those systems where it is
  2085. meaningful.
  2086.  
  2087. File: cpp.info,  Node: Output,  Next: Invocation,  Prev: Other Commands,  Up: Top
  2088.  
  2089. C Preprocessor Output
  2090. =====================
  2091.  
  2092.    The output from the C preprocessor looks much like the input, except
  2093. that all preprocessor command lines have been replaced with blank lines
  2094. and all comments with spaces.  Whitespace within a line is not altered;
  2095. however, a space is inserted after the expansions of most macro calls.
  2096.  
  2097.    Source file name and line number information is conveyed by lines of
  2098. the form
  2099.  
  2100.      # LINENUM FILENAME FLAGS
  2101.  
  2102. which are inserted as needed into the middle of the input (but never
  2103. within a string or character constant).  Such a line means that the
  2104. following line originated in file FILENAME at line LINENUM.
  2105.  
  2106.    After the file name comes zero or more flags, which are `1', `2' or
  2107. `3'.  If there are multiple flags, spaces separate them.  Here is what
  2108. the flags mean:
  2109.  
  2110. `1'
  2111.      This indicates the start of a new file.
  2112.  
  2113. `2'
  2114.      This indicates returning to a file (after having included another
  2115.      file).
  2116.  
  2117. `3'
  2118.      This indicates that the following text comes from a system header
  2119.      file, so certain warnings should be suppressed.
  2120.  
  2121. File: cpp.info,  Node: Invocation,  Next: Concept Index,  Prev: Output,  Up: Top
  2122.  
  2123. Invoking the C Preprocessor
  2124. ===========================
  2125.  
  2126.    Most often when you use the C preprocessor you will not have to
  2127. invoke it explicitly: the C compiler will do so automatically.
  2128. However, the preprocessor is sometimes useful on its own.
  2129.  
  2130.    The C preprocessor expects two file names as arguments, INFILE and
  2131. OUTFILE.  The preprocessor reads INFILE together with any other files
  2132. it specifies with `#include'.  All the output generated by the combined
  2133. input files is written in OUTFILE.
  2134.  
  2135.    Either INFILE or OUTFILE may be `-', which as INFILE means to read
  2136. from standard input and as OUTFILE means to write to standard output.
  2137. Also, if OUTFILE or both file names are omitted, the standard output
  2138. and standard input are used for the omitted file names.
  2139.  
  2140.    Here is a table of command options accepted by the C preprocessor.
  2141. These options can also be given when compiling a C program; they are
  2142. passed along automatically to the preprocessor when it is invoked by the
  2143. compiler.
  2144.  
  2145. `-P'
  2146.      Inhibit generation of `#'-lines with line-number information in
  2147.      the output from the preprocessor (*note Output::.).  This might be
  2148.      useful when running the preprocessor on something that is not C
  2149.      code and will be sent to a program which might be confused by the
  2150.      `#'-lines.
  2151.  
  2152. `-C'
  2153.      Do not discard comments: pass them through to the output file.
  2154.      Comments appearing in arguments of a macro call will be copied to
  2155.      the output before the expansion of the macro call.
  2156.  
  2157. `-traditional'
  2158.      Try to imitate the behavior of old-fashioned C, as opposed to ANSI
  2159.      C.
  2160.  
  2161.         * Traditional macro expansion pays no attention to singlequote
  2162.           or doublequote characters; macro argument symbols are
  2163.           replaced by the argument values even when they appear within
  2164.           apparent string or character constants.
  2165.  
  2166.         * Traditionally, it is permissible for a macro expansion to end
  2167.           in the middle of a string or character constant.  The
  2168.           constant continues into the text surrounding the macro call.
  2169.  
  2170.         * However, traditionally the end of the line terminates a
  2171.           string or character constant, with no error.
  2172.  
  2173.         * In traditional C, a comment is equivalent to no text at all.
  2174.           (In ANSI C, a comment counts as whitespace.)
  2175.  
  2176.         * Traditional C does not have the concept of a "preprocessing
  2177.           number".  It considers `1.0e+4' to be three tokens: `1.0e',
  2178.           `+', and `4'.
  2179.  
  2180.         * A macro is not suppressed within its own definition, in
  2181.           traditional C.  Thus, any macro that is used recursively
  2182.           inevitably causes an error.
  2183.  
  2184.         * The character `#' has no special meaning within a macro
  2185.           definition in traditional C.
  2186.  
  2187.         * In traditional C, the text at the end of a macro expansion
  2188.           can run together with the text after the macro call, to
  2189.           produce a single token.  (This is impossible in ANSI C.)
  2190.  
  2191.         * Traditionally, `\' inside a macro argument suppresses the
  2192.           syntactic significance of the following character.
  2193.  
  2194. `-trigraphs'
  2195.      Process ANSI standard trigraph sequences.  These are
  2196.      three-character sequences, all starting with `??', that are
  2197.      defined by ANSI C to stand for single characters.  For example,
  2198.      `??/' stands for `\', so `'??/n'' is a character constant for a
  2199.      newline.  Strictly speaking, the GNU C preprocessor does not
  2200.      support all programs in ANSI Standard C unless `-trigraphs' is
  2201.      used, but if you ever notice the difference it will be with relief.
  2202.  
  2203.      You don't want to know any more about trigraphs.
  2204.  
  2205. `-pedantic'
  2206.      Issue warnings required by the ANSI C standard in certain cases
  2207.      such as when text other than a comment follows `#else' or `#endif'.
  2208.  
  2209. `-pedantic-errors'
  2210.      Like `-pedantic', except that errors are produced rather than
  2211.      warnings.
  2212.  
  2213. `-Wtrigraphs'
  2214.      Warn if any trigraphs are encountered (assuming they are enabled).
  2215.  
  2216. `-Wcomment'
  2217.      Warn whenever a comment-start sequence `/*' appears in a comment.
  2218.  
  2219. `-Wall'
  2220.      Requests both `-Wtrigraphs' and `-Wcomment' (but not
  2221.      `-Wtraditional').
  2222.  
  2223. `-Wtraditional'
  2224.      Warn about certain constructs that behave differently in
  2225.      traditional and ANSI C.
  2226.  
  2227. `-I DIRECTORY'
  2228.      Add the directory DIRECTORY to the end of the list of directories
  2229.      to be searched for header files (*note Include Syntax::.).  This
  2230.      can be used to override a system header file, substituting your
  2231.      own version, since these directories are searched before the system
  2232.      header file directories.  If you use more than one `-I' option,
  2233.      the directories are scanned in left-to-right order; the standard
  2234.      system directories come after.
  2235.  
  2236. `-I-'
  2237.      Any directories specified with `-I' options before the `-I-'
  2238.      option are searched only for the case of `#include "FILE"'; they
  2239.      are not searched for `#include <FILE>'.
  2240.  
  2241.      If additional directories are specified with `-I' options after
  2242.      the `-I-', these directories are searched for all `#include'
  2243.      commands.
  2244.  
  2245.      In addition, the `-I-' option inhibits the use of the current
  2246.      directory as the first search directory for `#include "FILE"'.
  2247.      Therefore, the current directory is searched only if it is
  2248.      requested explicitly with `-I.'.  Specifying both `-I-' and `-I.'
  2249.      allows you to control precisely which directories are searched
  2250.      before the current one and which are searched after.
  2251.  
  2252. `-nostdinc'
  2253.      Do not search the standard system directories for header files.
  2254.      Only the directories you have specified with `-I' options (and the
  2255.      current directory, if appropriate) are searched.
  2256.  
  2257. `-nostdinc++'
  2258.      Do not search for header files in the C++-specific standard
  2259.      directories, but do still search the other standard directories.
  2260.      (This option is used when building libg++.)
  2261.  
  2262. `-D NAME'
  2263.      Predefine NAME as a macro, with definition `1'.
  2264.  
  2265. `-D NAME=DEFINITION'
  2266.      Predefine NAME as a macro, with definition DEFINITION.  There are
  2267.      no restrictions on the contents of DEFINITION, but if you are
  2268.      invoking the preprocessor from a shell or shell-like program you
  2269.      may need to use the shell's quoting syntax to protect characters
  2270.      such as spaces that have a meaning in the shell syntax.  If you
  2271.      use more than one `-D' for the same NAME, the rightmost definition
  2272.      takes effect.
  2273.  
  2274. `-U NAME'
  2275.      Do not predefine NAME.  If both `-U' and `-D' are specified for
  2276.      one name, the `-U' beats the `-D' and the name is not predefined.
  2277.  
  2278. `-undef'
  2279.      Do not predefine any nonstandard macros.
  2280.  
  2281. `-A PREDICATE(ANSWER)'
  2282.      Make an assertion with the predicate PREDICATE and answer ANSWER.
  2283.      *Note Assertions::.
  2284.  
  2285.      You can use `-A-' to disable all predefined assertions; it also
  2286.      undefines all predefined macros that identify the type of target
  2287.      system.
  2288.  
  2289. `-dM'
  2290.      Instead of outputting the result of preprocessing, output a list of
  2291.      `#define' commands for all the macros defined during the execution
  2292.      of the preprocessor, including predefined macros.  This gives you
  2293.      a way of finding out what is predefined in your version of the
  2294.      preprocessor; assuming you have no file `foo.h', the command
  2295.  
  2296.           touch foo.h; cpp -dM foo.h
  2297.  
  2298.      will show the values of any predefined macros.
  2299.  
  2300. `-dD'
  2301.      Like `-dM' except in two respects: it does *not* include the
  2302.      predefined macros, and it outputs *both* the `#define' commands
  2303.      and the result of preprocessing.  Both kinds of output go to the
  2304.      standard output file.
  2305.  
  2306. `-M [-MG]'
  2307.      Instead of outputting the result of preprocessing, output a rule
  2308.      suitable for `make' describing the dependencies of the main source
  2309.      file.  The preprocessor outputs one `make' rule containing the
  2310.      object file name for that source file, a colon, and the names of
  2311.      all the included files.  If there are many included files then the
  2312.      rule is split into several lines using `\'-newline.
  2313.  
  2314.      `-MG' says to treat missing header files as generated files and
  2315.      assume they live in the same directory as the source file.  It
  2316.      must be specified in addition to `-M'.
  2317.  
  2318.      This feature is used in automatic updating of makefiles.
  2319.  
  2320. `-MM [-MG]'
  2321.      Like `-M' but mention only the files included with `#include
  2322.      "FILE"'.  System header files included with `#include <FILE>' are
  2323.      omitted.
  2324.  
  2325. `-MD FILE'
  2326.      Like `-M' but the dependency information is written to FILE.  This
  2327.      is in addition to compiling the file as specified--`-MD' does not
  2328.      inhibit ordinary compilation the way `-M' does.
  2329.  
  2330.      When invoking gcc, do not specify the FILE argument.  Gcc will
  2331.      create file names made by replacing ".c" with ".d" at the end of
  2332.      the input file names.
  2333.  
  2334.      In Mach, you can use the utility `md' to merge multiple dependency
  2335.      files into a single dependency file suitable for using with the
  2336.      `make' command.
  2337.  
  2338. `-MMD FILE'
  2339.      Like `-MD' except mention only user header files, not system
  2340.      header files.
  2341.  
  2342. `-H'
  2343.      Print the name of each header file used, in addition to other
  2344.      normal activities.
  2345.  
  2346. `-imacros FILE'
  2347.      Process FILE as input, discarding the resulting output, before
  2348.      processing the regular input file.  Because the output generated
  2349.      from FILE is discarded, the only effect of `-imacros FILE' is to
  2350.      make the macros defined in FILE available for use in the main
  2351.      input.
  2352.  
  2353. `-include FILE'
  2354.      Process FILE as input, and include all the resulting output,
  2355.      before processing the regular input file.
  2356.  
  2357. `-idirafter DIR'
  2358.      Add the directory DIR to the second include path.  The directories
  2359.      on the second include path are searched when a header file is not
  2360.      found in any of the directories in the main include path (the one
  2361.      that `-I' adds to).
  2362.  
  2363. `-iprefix PREFIX'
  2364.      Specify PREFIX as the prefix for subsequent `-iwithprefix' options.
  2365.  
  2366. `-iwithprefix DIR'
  2367.      Add a directory to the second include path.  The directory's name
  2368.      is made by concatenating PREFIX and DIR, where PREFIX was
  2369.      specified previously with `-iprefix'.
  2370.  
  2371. `-isystem DIR'
  2372.      Add a directory to the beginning of the second include path,
  2373.      marking it as a system directory, so that it gets the same special
  2374.      treatment as is applied to the standard system directories.
  2375.  
  2376. `-lang-c'
  2377. `-lang-c++'
  2378. `-lang-objc'
  2379. `-lang-objc++'
  2380.      Specify the source language.  `-lang-c++' makes the preprocessor
  2381.      handle C++ comment syntax (comments may begin with `//', in which
  2382.      case they end at end of line), and includes extra default include
  2383.      directories for C++; and `-lang-objc' enables the Objective C
  2384.      `#import' command.  `-lang-c' explicitly turns off both of these
  2385.      extensions, and `-lang-objc++' enables both.
  2386.  
  2387.      These options are generated by the compiler driver `gcc', but not
  2388.      passed from the `gcc' command line.
  2389.  
  2390. `-lint'
  2391.      Look for commands to the program checker `lint' embedded in
  2392.      comments, and emit them preceded by `#pragma lint'.  For example,
  2393.      the comment `/* NOTREACHED */' becomes `#pragma lint NOTREACHED'.
  2394.  
  2395.      This option is available only when you call `cpp' directly; `gcc'
  2396.      will not pass it from its command line.
  2397.  
  2398. `-$'
  2399.      Forbid the use of `$' in identifiers.  This is required for ANSI
  2400.      conformance.  `gcc' automatically supplies this option to the
  2401.      preprocessor if you specify `-ansi', but `gcc' doesn't recognize
  2402.      the `-$' option itself--to use it without the other effects of
  2403.      `-ansi', you must call the preprocessor directly.
  2404.  
  2405. File: cpp.info,  Node: Concept Index,  Next: Index,  Prev: Invocation,  Up: Top
  2406.  
  2407. Concept Index
  2408. *************
  2409.  
  2410. * Menu:
  2411.  
  2412. * ##:                                   Concatenation.
  2413. * arguments in macro definitions:       Argument Macros.
  2414. * assertions:                           Assertions.
  2415. * assertions, undoing:                  Assertions.
  2416. * blank macro arguments:                Argument Macros.
  2417. * cascaded macros:                      Cascaded Macros.
  2418. * commands:                             Commands.
  2419. * commenting out code:                  Deleted Code.
  2420. * computed #include:                    Include Syntax.
  2421. * concatenation:                        Concatenation.
  2422. * conditionals:                         Conditionals.
  2423. * expansion of arguments:               Argument Prescan.
  2424. * function-like macro:                  Argument Macros.
  2425. * header file:                          Header Files.
  2426. * including just once:                  Once-Only.
  2427. * inheritance:                          Inheritance.
  2428. * invocation of the preprocessor:       Invocation.
  2429. * line control:                         Combining Sources.
  2430. * macro argument expansion:             Argument Prescan.
  2431. * macro body uses macro:                Cascaded Macros.
  2432. * macros with argument:                 Argument Macros.
  2433. * manifest constant:                    Simple Macros.
  2434. * newlines in macro arguments:          Newlines in Args.
  2435. * null command:                         Other Commands.
  2436. * options:                              Invocation.
  2437. * output format:                        Output.
  2438. * overriding a header file:             Inheritance.
  2439. * parentheses in macro bodies:          Macro Parentheses.
  2440. * pitfalls of macros:                   Macro Pitfalls.
  2441. * predefined macros:                    Predefined.
  2442. * predicates:                           Assertions.
  2443. * preprocessor commands:                Commands.
  2444. * prescan of macro arguments:           Argument Prescan.
  2445. * problems with macros:                 Macro Pitfalls.
  2446. * redefining macros:                    Redefining.
  2447. * repeated inclusion:                   Once-Only.
  2448. * retracting assertions:                Assertions.
  2449. * second include path:                  Invocation.
  2450. * self-reference:                       Self-Reference.
  2451. * semicolons (after macro calls):       Swallow Semicolon.
  2452. * side effects (in macro arguments):    Side Effects.
  2453. * simple macro:                         Simple Macros.
  2454. * space as macro argument:              Argument Macros.
  2455. * standard predefined macros:           Standard Predefined.
  2456. * stringification:                      Stringification.
  2457. * testing predicates:                   Assertions.
  2458. * unassert:                             Assertions.
  2459. * undefining macros:                    Undefining.
  2460. * unsafe macros:                        Side Effects.
  2461.  
  2462. File: cpp.info,  Node: Index,  Prev: Concept Index,  Up: Top
  2463.  
  2464. Index of Commands, Macros and Options
  2465. *************************************
  2466.  
  2467. * Menu:
  2468.  
  2469. * #assert:                              Assertions.
  2470. * #cpu:                                 Assertions.
  2471. * #define:                              Argument Macros.
  2472. * #elif:                                #elif Command.
  2473. * #else:                                #else Command.
  2474. * #error:                               #error Command.
  2475. * #ident:                               Other Commands.
  2476. * #if:                                  Conditional Syntax.
  2477. * #ifdef:                               Conditionals-Macros.
  2478. * #ifndef:                              Conditionals-Macros.
  2479. * #import:                              Once-Only.
  2480. * #include:                             Include Syntax.
  2481. * #include_next:                        Inheritance.
  2482. * #line:                                Combining Sources.
  2483. * #machine:                             Assertions.
  2484. * #pragma:                              Other Commands.
  2485. * #pragma once:                         Once-Only.
  2486. * #system:                              Assertions.
  2487. * #unassert:                            Assertions.
  2488. * #warning:                             #error Command.
  2489. * -$:                                   Invocation.
  2490. * -A:                                   Invocation.
  2491. * -C:                                   Invocation.
  2492. * -D:                                   Invocation.
  2493. * -dD:                                  Invocation.
  2494. * -dM:                                  Invocation.
  2495. * -H:                                   Invocation.
  2496. * -I:                                   Invocation.
  2497. * -idirafter:                           Invocation.
  2498. * -imacros:                             Invocation.
  2499. * -include:                             Invocation.
  2500. * -iprefix:                             Invocation.
  2501. * -isystem:                             Invocation.
  2502. * -iwithprefix:                         Invocation.
  2503. * -lang-c:                              Invocation.
  2504. * -lang-c++:                            Invocation.
  2505. * -lang-objc:                           Invocation.
  2506. * -lang-objc++:                         Invocation.
  2507. * -M:                                   Invocation.
  2508. * -MD:                                  Invocation.
  2509. * -MM:                                  Invocation.
  2510. * -MMD:                                 Invocation.
  2511. * -nostdinc:                            Invocation.
  2512. * -nostdinc++:                          Invocation.
  2513. * -P:                                   Invocation.
  2514. * -pedantic:                            Invocation.
  2515. * -pedantic-errors:                     Invocation.
  2516. * -traditional:                         Invocation.
  2517. * -trigraphs:                           Invocation.
  2518. * -U:                                   Invocation.
  2519. * -undef:                               Invocation.
  2520. * -Wall:                                Invocation.
  2521. * -Wcomment:                            Invocation.
  2522. * -Wtraditional:                        Invocation.
  2523. * -Wtrigraphs:                          Invocation.
  2524. * BSD:                                  Nonstandard Predefined.
  2525. * defined:                              Conditionals-Macros.
  2526. * M68020:                               Nonstandard Predefined.
  2527. * m68k:                                 Nonstandard Predefined.
  2528. * mc68000:                              Nonstandard Predefined.
  2529. * ns32000:                              Nonstandard Predefined.
  2530. * pyr:                                  Nonstandard Predefined.
  2531. * sequent:                              Nonstandard Predefined.
  2532. * sun:                                  Nonstandard Predefined.
  2533. * system header files:                  Header Uses.
  2534. * unix:                                 Nonstandard Predefined.
  2535. * vax:                                  Nonstandard Predefined.
  2536. * _AM29000:                             Nonstandard Predefined.
  2537. * _AM29K:                               Nonstandard Predefined.
  2538. * __BASE_FILE__:                        Standard Predefined.
  2539. * __CHAR_UNSIGNED__:                    Standard Predefined.
  2540. * __cplusplus:                          Standard Predefined.
  2541. * __DATE__:                             Standard Predefined.
  2542. * __FILE__:                             Standard Predefined.
  2543. * __GNUC__:                             Standard Predefined.
  2544. * __GNUG__:                             Standard Predefined.
  2545. * __INCLUDE_LEVEL_:                     Standard Predefined.
  2546. * __LINE__:                             Standard Predefined.
  2547. * __OPTIMIZE__:                         Standard Predefined.
  2548. * __STDC__:                             Standard Predefined.
  2549. * __STRICT_ANSI__:                      Standard Predefined.
  2550. * __TIME__:                             Standard Predefined.
  2551. * __VERSION__:                          Standard Predefined.
  2552.  
  2553.  
  2554. Tag Table:
  2555. Node: Top778
  2556. Node: Global Actions3339
  2557. Node: Commands5843
  2558. Node: Header Files7487
  2559. Node: Header Uses8139
  2560. Node: Include Syntax9631
  2561. Node: Include Operation12761
  2562. Node: Once-Only14617
  2563. Node: Inheritance17040
  2564. Node: Macros19600
  2565. Node: Simple Macros20514
  2566. Node: Argument Macros23495
  2567. Node: Predefined29291
  2568. Node: Standard Predefined29721
  2569. Node: Nonstandard Predefined35176
  2570. Node: Stringification38752
  2571. Node: Concatenation41678
  2572. Node: Undefining44951
  2573. Node: Redefining45984
  2574. Node: Macro Pitfalls47284
  2575. Node: Misnesting48388
  2576. Node: Macro Parentheses49402
  2577. Node: Swallow Semicolon51279
  2578. Node: Side Effects53179
  2579. Node: Self-Reference54877
  2580. Node: Argument Prescan57153
  2581. Node: Cascaded Macros62155
  2582. Node: Newlines in Args63300
  2583. Node: Conditionals64645
  2584. Node: Conditional Uses65991
  2585. Node: Conditional Syntax67412
  2586. Node: #if Command67990
  2587. Node: #else Command70262
  2588. Node: #elif Command70917
  2589. Node: Deleted Code72279
  2590. Node: Conditionals-Macros73340
  2591. Node: Assertions77018
  2592. Node: #error Command81248
  2593. Node: Combining Sources82676
  2594. Node: Other Commands85572
  2595. Node: Output87007
  2596. Node: Invocation88162
  2597. Node: Concept Index99783
  2598. Node: Index102581
  2599. End Tag Table
  2600.