OSDN Git Service

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