1This is doc/cpp.info, produced by makeinfo version 4.8 from 2/projects/toolchains_build/buildroot-2012.02-brcm/output/toolchain/gcc-4.5.3/gcc/doc/cpp.texi. 3 4 Copyright (C) 1987, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 51998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 62010, 2011 Free Software Foundation, Inc. 7 8 Permission is granted to copy, distribute and/or modify this document 9under the terms of the GNU Free Documentation License, Version 1.2 or 10any later version published by the Free Software Foundation. A copy of 11the license is included in the section entitled "GNU Free Documentation 12License". 13 14 This manual contains no Invariant Sections. The Front-Cover Texts 15are (a) (see below), and the Back-Cover Texts are (b) (see below). 16 17 (a) The FSF's Front-Cover Text is: 18 19 A GNU Manual 20 21 (b) The FSF's Back-Cover Text is: 22 23 You have freedom to copy and modify this GNU Manual, like GNU 24software. Copies published by the Free Software Foundation raise 25funds for GNU development. 26 27INFO-DIR-SECTION Software development 28START-INFO-DIR-ENTRY 29* Cpp: (cpp). The GNU C preprocessor. 30END-INFO-DIR-ENTRY 31 32 33File: cpp.info, Node: Top, Next: Overview, Up: (dir) 34 35The C Preprocessor 36****************** 37 38The C preprocessor implements the macro language used to transform C, 39C++, and Objective-C programs before they are compiled. It can also be 40useful on its own. 41 42* Menu: 43 44* Overview:: 45* Header Files:: 46* Macros:: 47* Conditionals:: 48* Diagnostics:: 49* Line Control:: 50* Pragmas:: 51* Other Directives:: 52* Preprocessor Output:: 53* Traditional Mode:: 54* Implementation Details:: 55* Invocation:: 56* Environment Variables:: 57* GNU Free Documentation License:: 58* Index of Directives:: 59* Option Index:: 60* Concept Index:: 61 62 --- The Detailed Node Listing --- 63 64Overview 65 66* Character sets:: 67* Initial processing:: 68* Tokenization:: 69* The preprocessing language:: 70 71Header Files 72 73* Include Syntax:: 74* Include Operation:: 75* Search Path:: 76* Once-Only Headers:: 77* Alternatives to Wrapper #ifndef:: 78* Computed Includes:: 79* Wrapper Headers:: 80* System Headers:: 81 82Macros 83 84* Object-like Macros:: 85* Function-like Macros:: 86* Macro Arguments:: 87* Stringification:: 88* Concatenation:: 89* Variadic Macros:: 90* Predefined Macros:: 91* Undefining and Redefining Macros:: 92* Directives Within Macro Arguments:: 93* Macro Pitfalls:: 94 95Predefined Macros 96 97* Standard Predefined Macros:: 98* Common Predefined Macros:: 99* System-specific Predefined Macros:: 100* C++ Named Operators:: 101 102Macro Pitfalls 103 104* Misnesting:: 105* Operator Precedence Problems:: 106* Swallowing the Semicolon:: 107* Duplication of Side Effects:: 108* Self-Referential Macros:: 109* Argument Prescan:: 110* Newlines in Arguments:: 111 112Conditionals 113 114* Conditional Uses:: 115* Conditional Syntax:: 116* Deleted Code:: 117 118Conditional Syntax 119 120* Ifdef:: 121* If:: 122* Defined:: 123* Else:: 124* Elif:: 125 126Implementation Details 127 128* Implementation-defined behavior:: 129* Implementation limits:: 130* Obsolete Features:: 131* Differences from previous versions:: 132 133Obsolete Features 134 135* Obsolete Features:: 136 137 Copyright (C) 1987, 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1381998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 1392010, 2011 Free Software Foundation, Inc. 140 141 Permission is granted to copy, distribute and/or modify this document 142under the terms of the GNU Free Documentation License, Version 1.2 or 143any later version published by the Free Software Foundation. A copy of 144the license is included in the section entitled "GNU Free Documentation 145License". 146 147 This manual contains no Invariant Sections. The Front-Cover Texts 148are (a) (see below), and the Back-Cover Texts are (b) (see below). 149 150 (a) The FSF's Front-Cover Text is: 151 152 A GNU Manual 153 154 (b) The FSF's Back-Cover Text is: 155 156 You have freedom to copy and modify this GNU Manual, like GNU 157software. Copies published by the Free Software Foundation raise 158funds for GNU development. 159 160 161File: cpp.info, Node: Overview, Next: Header Files, Prev: Top, Up: Top 162 1631 Overview 164********** 165 166The C preprocessor, often known as "cpp", is a "macro processor" that 167is used automatically by the C compiler to transform your program 168before compilation. It is called a macro processor because it allows 169you to define "macros", which are brief abbreviations for longer 170constructs. 171 172 The C preprocessor is intended to be used only with C, C++, and 173Objective-C source code. In the past, it has been abused as a general 174text processor. It will choke on input which does not obey C's lexical 175rules. For example, apostrophes will be interpreted as the beginning of 176character constants, and cause errors. Also, you cannot rely on it 177preserving characteristics of the input which are not significant to 178C-family languages. If a Makefile is preprocessed, all the hard tabs 179will be removed, and the Makefile will not work. 180 181 Having said that, you can often get away with using cpp on things 182which are not C. Other Algol-ish programming languages are often safe 183(Pascal, Ada, etc.) So is assembly, with caution. `-traditional-cpp' 184mode preserves more white space, and is otherwise more permissive. Many 185of the problems can be avoided by writing C or C++ style comments 186instead of native language comments, and keeping macros simple. 187 188 Wherever possible, you should use a preprocessor geared to the 189language you are writing in. Modern versions of the GNU assembler have 190macro facilities. Most high level programming languages have their own 191conditional compilation and inclusion mechanism. If all else fails, 192try a true general text processor, such as GNU M4. 193 194 C preprocessors vary in some details. This manual discusses the GNU 195C preprocessor, which provides a small superset of the features of ISO 196Standard C. In its default mode, the GNU C preprocessor does not do a 197few things required by the standard. These are features which are 198rarely, if ever, used, and may cause surprising changes to the meaning 199of a program which does not expect them. To get strict ISO Standard C, 200you should use the `-std=c90' or `-std=c99' options, depending on which 201version of the standard you want. To get all the mandatory 202diagnostics, you must also use `-pedantic'. *Note Invocation::. 203 204 This manual describes the behavior of the ISO preprocessor. To 205minimize gratuitous differences, where the ISO preprocessor's behavior 206does not conflict with traditional semantics, the traditional 207preprocessor should behave the same way. The various differences that 208do exist are detailed in the section *Note Traditional Mode::. 209 210 For clarity, unless noted otherwise, references to `CPP' in this 211manual refer to GNU CPP. 212 213* Menu: 214 215* Character sets:: 216* Initial processing:: 217* Tokenization:: 218* The preprocessing language:: 219 220 221File: cpp.info, Node: Character sets, Next: Initial processing, Up: Overview 222 2231.1 Character sets 224================== 225 226Source code character set processing in C and related languages is 227rather complicated. The C standard discusses two character sets, but 228there are really at least four. 229 230 The files input to CPP might be in any character set at all. CPP's 231very first action, before it even looks for line boundaries, is to 232convert the file into the character set it uses for internal 233processing. That set is what the C standard calls the "source" 234character set. It must be isomorphic with ISO 10646, also known as 235Unicode. CPP uses the UTF-8 encoding of Unicode. 236 237 The character sets of the input files are specified using the 238`-finput-charset=' option. 239 240 All preprocessing work (the subject of the rest of this manual) is 241carried out in the source character set. If you request textual output 242from the preprocessor with the `-E' option, it will be in UTF-8. 243 244 After preprocessing is complete, string and character constants are 245converted again, into the "execution" character set. This character 246set is under control of the user; the default is UTF-8, matching the 247source character set. Wide string and character constants have their 248own character set, which is not called out specifically in the 249standard. Again, it is under control of the user. The default is 250UTF-16 or UTF-32, whichever fits in the target's `wchar_t' type, in the 251target machine's byte order.(1) Octal and hexadecimal escape sequences 252do not undergo conversion; '\x12' has the value 0x12 regardless of the 253currently selected execution character set. All other escapes are 254replaced by the character in the source character set that they 255represent, then converted to the execution character set, just like 256unescaped characters. 257 258 Unless the experimental `-fextended-identifiers' option is used, GCC 259does not permit the use of characters outside the ASCII range, nor `\u' 260and `\U' escapes, in identifiers. Even with that option, characters 261outside the ASCII range can only be specified with the `\u' and `\U' 262escapes, not used directly in identifiers. 263 264 ---------- Footnotes ---------- 265 266 (1) UTF-16 does not meet the requirements of the C standard for a 267wide character set, but the choice of 16-bit `wchar_t' is enshrined in 268some system ABIs so we cannot fix this. 269 270 271File: cpp.info, Node: Initial processing, Next: Tokenization, Prev: Character sets, Up: Overview 272 2731.2 Initial processing 274====================== 275 276The preprocessor performs a series of textual transformations on its 277input. These happen before all other processing. Conceptually, they 278happen in a rigid order, and the entire file is run through each 279transformation before the next one begins. CPP actually does them all 280at once, for performance reasons. These transformations correspond 281roughly to the first three "phases of translation" described in the C 282standard. 283 284 1. The input file is read into memory and broken into lines. 285 286 Different systems use different conventions to indicate the end of 287 a line. GCC accepts the ASCII control sequences `LF', `CR LF' and 288 `CR' as end-of-line markers. These are the canonical sequences 289 used by Unix, DOS and VMS, and the classic Mac OS (before OSX) 290 respectively. You may therefore safely copy source code written 291 on any of those systems to a different one and use it without 292 conversion. (GCC may lose track of the current line number if a 293 file doesn't consistently use one convention, as sometimes happens 294 when it is edited on computers with different conventions that 295 share a network file system.) 296 297 If the last line of any input file lacks an end-of-line marker, 298 the end of the file is considered to implicitly supply one. The C 299 standard says that this condition provokes undefined behavior, so 300 GCC will emit a warning message. 301 302 2. If trigraphs are enabled, they are replaced by their corresponding 303 single characters. By default GCC ignores trigraphs, but if you 304 request a strictly conforming mode with the `-std' option, or you 305 specify the `-trigraphs' option, then it converts them. 306 307 These are nine three-character sequences, all starting with `??', 308 that are defined by ISO C to stand for single characters. They 309 permit obsolete systems that lack some of C's punctuation to use 310 C. For example, `??/' stands for `\', so '??/n' is a character 311 constant for a newline. 312 313 Trigraphs are not popular and many compilers implement them 314 incorrectly. Portable code should not rely on trigraphs being 315 either converted or ignored. With `-Wtrigraphs' GCC will warn you 316 when a trigraph may change the meaning of your program if it were 317 converted. *Note Wtrigraphs::. 318 319 In a string constant, you can prevent a sequence of question marks 320 from being confused with a trigraph by inserting a backslash 321 between the question marks, or by separating the string literal at 322 the trigraph and making use of string literal concatenation. 323 "(??\?)" is the string `(???)', not `(?]'. Traditional C 324 compilers do not recognize these idioms. 325 326 The nine trigraphs and their replacements are 327 328 Trigraph: ??( ??) ??< ??> ??= ??/ ??' ??! ??- 329 Replacement: [ ] { } # \ ^ | ~ 330 331 3. Continued lines are merged into one long line. 332 333 A continued line is a line which ends with a backslash, `\'. The 334 backslash is removed and the following line is joined with the 335 current one. No space is inserted, so you may split a line 336 anywhere, even in the middle of a word. (It is generally more 337 readable to split lines only at white space.) 338 339 The trailing backslash on a continued line is commonly referred to 340 as a "backslash-newline". 341 342 If there is white space between a backslash and the end of a line, 343 that is still a continued line. However, as this is usually the 344 result of an editing mistake, and many compilers will not accept 345 it as a continued line, GCC will warn you about it. 346 347 4. All comments are replaced with single spaces. 348 349 There are two kinds of comments. "Block comments" begin with `/*' 350 and continue until the next `*/'. Block comments do not nest: 351 352 /* this is /* one comment */ text outside comment 353 354 "Line comments" begin with `//' and continue to the end of the 355 current line. Line comments do not nest either, but it does not 356 matter, because they would end in the same place anyway. 357 358 // this is // one comment 359 text outside comment 360 361 It is safe to put line comments inside block comments, or vice versa. 362 363 /* block comment 364 // contains line comment 365 yet more comment 366 */ outside comment 367 368 // line comment /* contains block comment */ 369 370 But beware of commenting out one end of a block comment with a line 371comment. 372 373 // l.c. /* block comment begins 374 oops! this isn't a comment anymore */ 375 376 Comments are not recognized within string literals. "/* blah */" is 377the string constant `/* blah */', not an empty string. 378 379 Line comments are not in the 1989 edition of the C standard, but they 380are recognized by GCC as an extension. In C++ and in the 1999 edition 381of the C standard, they are an official part of the language. 382 383 Since these transformations happen before all other processing, you 384can split a line mechanically with backslash-newline anywhere. You can 385comment out the end of a line. You can continue a line comment onto the 386next line with backslash-newline. You can even split `/*', `*/', and 387`//' onto multiple lines with backslash-newline. For example: 388 389 /\ 390 * 391 */ # /* 392 */ defi\ 393 ne FO\ 394 O 10\ 395 20 396 397is equivalent to `#define FOO 1020'. All these tricks are extremely 398confusing and should not be used in code intended to be readable. 399 400 There is no way to prevent a backslash at the end of a line from 401being interpreted as a backslash-newline. This cannot affect any 402correct program, however. 403 404 405File: cpp.info, Node: Tokenization, Next: The preprocessing language, Prev: Initial processing, Up: Overview 406 4071.3 Tokenization 408================ 409 410After the textual transformations are finished, the input file is 411converted into a sequence of "preprocessing tokens". These mostly 412correspond to the syntactic tokens used by the C compiler, but there are 413a few differences. White space separates tokens; it is not itself a 414token of any kind. Tokens do not have to be separated by white space, 415but it is often necessary to avoid ambiguities. 416 417 When faced with a sequence of characters that has more than one 418possible tokenization, the preprocessor is greedy. It always makes 419each token, starting from the left, as big as possible before moving on 420to the next token. For instance, `a+++++b' is interpreted as 421`a ++ ++ + b', not as `a ++ + ++ b', even though the latter 422tokenization could be part of a valid C program and the former could 423not. 424 425 Once the input file is broken into tokens, the token boundaries never 426change, except when the `##' preprocessing operator is used to paste 427tokens together. *Note Concatenation::. For example, 428 429 #define foo() bar 430 foo()baz 431 ==> bar baz 432 _not_ 433 ==> barbaz 434 435 The compiler does not re-tokenize the preprocessor's output. Each 436preprocessing token becomes one compiler token. 437 438 Preprocessing tokens fall into five broad classes: identifiers, 439preprocessing numbers, string literals, punctuators, and other. An 440"identifier" is the same as an identifier in C: any sequence of 441letters, digits, or underscores, which begins with a letter or 442underscore. Keywords of C have no significance to the preprocessor; 443they are ordinary identifiers. You can define a macro whose name is a 444keyword, for instance. The only identifier which can be considered a 445preprocessing keyword is `defined'. *Note Defined::. 446 447 This is mostly true of other languages which use the C preprocessor. 448However, a few of the keywords of C++ are significant even in the 449preprocessor. *Note C++ Named Operators::. 450 451 In the 1999 C standard, identifiers may contain letters which are not 452part of the "basic source character set", at the implementation's 453discretion (such as accented Latin letters, Greek letters, or Chinese 454ideograms). This may be done with an extended character set, or the 455`\u' and `\U' escape sequences. The implementation of this feature in 456GCC is experimental; such characters are only accepted in the `\u' and 457`\U' forms and only if `-fextended-identifiers' is used. 458 459 As an extension, GCC treats `$' as a letter. This is for 460compatibility with some systems, such as VMS, where `$' is commonly 461used in system-defined function and object names. `$' is not a letter 462in strictly conforming mode, or if you specify the `-$' option. *Note 463Invocation::. 464 465 A "preprocessing number" has a rather bizarre definition. The 466category includes all the normal integer and floating point constants 467one expects of C, but also a number of other things one might not 468initially recognize as a number. Formally, preprocessing numbers begin 469with an optional period, a required decimal digit, and then continue 470with any sequence of letters, digits, underscores, periods, and 471exponents. Exponents are the two-character sequences `e+', `e-', `E+', 472`E-', `p+', `p-', `P+', and `P-'. (The exponents that begin with `p' 473or `P' are new to C99. They are used for hexadecimal floating-point 474constants.) 475 476 The purpose of this unusual definition is to isolate the preprocessor 477from the full complexity of numeric constants. It does not have to 478distinguish between lexically valid and invalid floating-point numbers, 479which is complicated. The definition also permits you to split an 480identifier at any position and get exactly two tokens, which can then be 481pasted back together with the `##' operator. 482 483 It's possible for preprocessing numbers to cause programs to be 484misinterpreted. For example, `0xE+12' is a preprocessing number which 485does not translate to any valid numeric constant, therefore a syntax 486error. It does not mean `0xE + 12', which is what you might have 487intended. 488 489 "String literals" are string constants, character constants, and 490header file names (the argument of `#include').(1) String constants 491and character constants are straightforward: "..." or '...'. In either 492case embedded quotes should be escaped with a backslash: '\'' is the 493character constant for `''. There is no limit on the length of a 494character constant, but the value of a character constant that contains 495more than one character is implementation-defined. *Note 496Implementation Details::. 497 498 Header file names either look like string constants, "...", or are 499written with angle brackets instead, <...>. In either case, backslash 500is an ordinary character. There is no way to escape the closing quote 501or angle bracket. The preprocessor looks for the header file in 502different places depending on which form you use. *Note Include 503Operation::. 504 505 No string literal may extend past the end of a line. Older versions 506of GCC accepted multi-line string constants. You may use continued 507lines instead, or string constant concatenation. *Note Differences 508from previous versions::. 509 510 "Punctuators" are all the usual bits of punctuation which are 511meaningful to C and C++. All but three of the punctuation characters in 512ASCII are C punctuators. The exceptions are `@', `$', and ``'. In 513addition, all the two- and three-character operators are punctuators. 514There are also six "digraphs", which the C++ standard calls 515"alternative tokens", which are merely alternate ways to spell other 516punctuators. This is a second attempt to work around missing 517punctuation in obsolete systems. It has no negative side effects, 518unlike trigraphs, but does not cover as much ground. The digraphs and 519their corresponding normal punctuators are: 520 521 Digraph: <% %> <: :> %: %:%: 522 Punctuator: { } [ ] # ## 523 524 Any other single character is considered "other". It is passed on to 525the preprocessor's output unmolested. The C compiler will almost 526certainly reject source code containing "other" tokens. In ASCII, the 527only other characters are `@', `$', ``', and control characters other 528than NUL (all bits zero). (Note that `$' is normally considered a 529letter.) All characters with the high bit set (numeric range 5300x7F-0xFF) are also "other" in the present implementation. This will 531change when proper support for international character sets is added to 532GCC. 533 534 NUL is a special case because of the high probability that its 535appearance is accidental, and because it may be invisible to the user 536(many terminals do not display NUL at all). Within comments, NULs are 537silently ignored, just as any other character would be. In running 538text, NUL is considered white space. For example, these two directives 539have the same meaning. 540 541 #define X^@1 542 #define X 1 543 544(where `^@' is ASCII NUL). Within string or character constants, NULs 545are preserved. In the latter two cases the preprocessor emits a 546warning message. 547 548 ---------- Footnotes ---------- 549 550 (1) The C standard uses the term "string literal" to refer only to 551what we are calling "string constants". 552 553 554File: cpp.info, Node: The preprocessing language, Prev: Tokenization, Up: Overview 555 5561.4 The preprocessing language 557============================== 558 559After tokenization, the stream of tokens may simply be passed straight 560to the compiler's parser. However, if it contains any operations in the 561"preprocessing language", it will be transformed first. This stage 562corresponds roughly to the standard's "translation phase 4" and is what 563most people think of as the preprocessor's job. 564 565 The preprocessing language consists of "directives" to be executed 566and "macros" to be expanded. Its primary capabilities are: 567 568 * Inclusion of header files. These are files of declarations that 569 can be substituted into your program. 570 571 * Macro expansion. You can define "macros", which are abbreviations 572 for arbitrary fragments of C code. The preprocessor will replace 573 the macros with their definitions throughout the program. Some 574 macros are automatically defined for you. 575 576 * Conditional compilation. You can include or exclude parts of the 577 program according to various conditions. 578 579 * Line control. If you use a program to combine or rearrange source 580 files into an intermediate file which is then compiled, you can 581 use line control to inform the compiler where each source line 582 originally came from. 583 584 * Diagnostics. You can detect problems at compile time and issue 585 errors or warnings. 586 587 There are a few more, less useful, features. 588 589 Except for expansion of predefined macros, all these operations are 590triggered with "preprocessing directives". Preprocessing directives 591are lines in your program that start with `#'. Whitespace is allowed 592before and after the `#'. The `#' is followed by an identifier, the 593"directive name". It specifies the operation to perform. Directives 594are commonly referred to as `#NAME' where NAME is the directive name. 595For example, `#define' is the directive that defines a macro. 596 597 The `#' which begins a directive cannot come from a macro expansion. 598Also, the directive name is not macro expanded. Thus, if `foo' is 599defined as a macro expanding to `define', that does not make `#foo' a 600valid preprocessing directive. 601 602 The set of valid directive names is fixed. Programs cannot define 603new preprocessing directives. 604 605 Some directives require arguments; these make up the rest of the 606directive line and must be separated from the directive name by 607whitespace. For example, `#define' must be followed by a macro name 608and the intended expansion of the macro. 609 610 A preprocessing directive cannot cover more than one line. The line 611may, however, be continued with backslash-newline, or by a block comment 612which extends past the end of the line. In either case, when the 613directive is processed, the continuations have already been merged with 614the first line to make one long line. 615 616 617File: cpp.info, Node: Header Files, Next: Macros, Prev: Overview, Up: Top 618 6192 Header Files 620************** 621 622A header file is a file containing C declarations and macro definitions 623(*note Macros::) to be shared between several source files. You request 624the use of a header file in your program by "including" it, with the C 625preprocessing directive `#include'. 626 627 Header files serve two purposes. 628 629 * System header files declare the interfaces to parts of the 630 operating system. You include them in your program to supply the 631 definitions and declarations you need to invoke system calls and 632 libraries. 633 634 * Your own header files contain declarations for interfaces between 635 the source files of your program. Each time you have a group of 636 related declarations and macro definitions all or most of which 637 are needed in several different source files, it is a good idea to 638 create a header file for them. 639 640 Including a header file produces the same results as copying the 641header file into each source file that needs it. Such copying would be 642time-consuming and error-prone. With a header file, the related 643declarations appear in only one place. If they need to be changed, they 644can be changed in one place, and programs that include the header file 645will automatically use the new version when next recompiled. The header 646file eliminates the labor of finding and changing all the copies as well 647as the risk that a failure to find one copy will result in 648inconsistencies within a program. 649 650 In C, the usual convention is to give header files names that end 651with `.h'. It is most portable to use only letters, digits, dashes, and 652underscores in header file names, and at most one dot. 653 654* Menu: 655 656* Include Syntax:: 657* Include Operation:: 658* Search Path:: 659* Once-Only Headers:: 660* Alternatives to Wrapper #ifndef:: 661* Computed Includes:: 662* Wrapper Headers:: 663* System Headers:: 664 665 666File: cpp.info, Node: Include Syntax, Next: Include Operation, Up: Header Files 667 6682.1 Include Syntax 669================== 670 671Both user and system header files are included using the preprocessing 672directive `#include'. It has two variants: 673 674`#include <FILE>' 675 This variant is used for system header files. It searches for a 676 file named FILE in a standard list of system directories. You can 677 prepend directories to this list with the `-I' option (*note 678 Invocation::). 679 680`#include "FILE"' 681 This variant is used for header files of your own program. It 682 searches for a file named FILE first in the directory containing 683 the current file, then in the quote directories and then the same 684 directories used for `<FILE>'. You can prepend directories to the 685 list of quote directories with the `-iquote' option. 686 687 The argument of `#include', whether delimited with quote marks or 688angle brackets, behaves like a string constant in that comments are not 689recognized, and macro names are not expanded. Thus, `#include <x/*y>' 690specifies inclusion of a system header file named `x/*y'. 691 692 However, if backslashes occur within FILE, they are considered 693ordinary text characters, not escape characters. None of the character 694escape sequences appropriate to string constants in C are processed. 695Thus, `#include "x\n\\y"' specifies a filename containing three 696backslashes. (Some systems interpret `\' as a pathname separator. All 697of these also interpret `/' the same way. It is most portable to use 698only `/'.) 699 700 It is an error if there is anything (other than comments) on the line 701after the file name. 702 703 704File: cpp.info, Node: Include Operation, Next: Search Path, Prev: Include Syntax, Up: Header Files 705 7062.2 Include Operation 707===================== 708 709The `#include' directive works by directing the C preprocessor to scan 710the specified file as input before continuing with the rest of the 711current file. The output from the preprocessor contains the output 712already generated, followed by the output resulting from the included 713file, followed by the output that comes from the text after the 714`#include' directive. For example, if you have a header file 715`header.h' as follows, 716 717 char *test (void); 718 719and a main program called `program.c' that uses the header file, like 720this, 721 722 int x; 723 #include "header.h" 724 725 int 726 main (void) 727 { 728 puts (test ()); 729 } 730 731the compiler will see the same token stream as it would if `program.c' 732read 733 734 int x; 735 char *test (void); 736 737 int 738 main (void) 739 { 740 puts (test ()); 741 } 742 743 Included files are not limited to declarations and macro definitions; 744those are merely the typical uses. Any fragment of a C program can be 745included from another file. The include file could even contain the 746beginning of a statement that is concluded in the containing file, or 747the end of a statement that was started in the including file. However, 748an included file must consist of complete tokens. Comments and string 749literals which have not been closed by the end of an included file are 750invalid. For error recovery, they are considered to end at the end of 751the file. 752 753 To avoid confusion, it is best if header files contain only complete 754syntactic units--function declarations or definitions, type 755declarations, etc. 756 757 The line following the `#include' directive is always treated as a 758separate line by the C preprocessor, even if the included file lacks a 759final newline. 760 761 762File: cpp.info, Node: Search Path, Next: Once-Only Headers, Prev: Include Operation, Up: Header Files 763 7642.3 Search Path 765=============== 766 767GCC looks in several different places for headers. On a normal Unix 768system, if you do not instruct it otherwise, it will look for headers 769requested with `#include <FILE>' in: 770 771 /usr/local/include 772 LIBDIR/gcc/TARGET/VERSION/include 773 /usr/TARGET/include 774 /usr/include 775 776 For C++ programs, it will also look in `/usr/include/g++-v3', first. 777In the above, TARGET is the canonical name of the system GCC was 778configured to compile code for; often but not always the same as the 779canonical name of the system it runs on. VERSION is the version of GCC 780in use. 781 782 You can add to this list with the `-IDIR' command line option. All 783the directories named by `-I' are searched, in left-to-right order, 784_before_ the default directories. The only exception is when `dir' is 785already searched by default. In this case, the option is ignored and 786the search order for system directories remains unchanged. 787 788 Duplicate directories are removed from the quote and bracket search 789chains before the two chains are merged to make the final search chain. 790Thus, it is possible for a directory to occur twice in the final search 791chain if it was specified in both the quote and bracket chains. 792 793 You can prevent GCC from searching any of the default directories 794with the `-nostdinc' option. This is useful when you are compiling an 795operating system kernel or some other program that does not use the 796standard C library facilities, or the standard C library itself. `-I' 797options are not ignored as described above when `-nostdinc' is in 798effect. 799 800 GCC looks for headers requested with `#include "FILE"' first in the 801directory containing the current file, then in the directories as 802specified by `-iquote' options, then in the same places it would have 803looked for a header requested with angle brackets. For example, if 804`/usr/include/sys/stat.h' contains `#include "types.h"', GCC looks for 805`types.h' first in `/usr/include/sys', then in its usual search path. 806 807 `#line' (*note Line Control::) does not change GCC's idea of the 808directory containing the current file. 809 810 You may put `-I-' at any point in your list of `-I' options. This 811has two effects. First, directories appearing before the `-I-' in the 812list are searched only for headers requested with quote marks. 813Directories after `-I-' are searched for all headers. Second, the 814directory containing the current file is not searched for anything, 815unless it happens to be one of the directories named by an `-I' switch. 816`-I-' is deprecated, `-iquote' should be used instead. 817 818 `-I. -I-' is not the same as no `-I' options at all, and does not 819cause the same behavior for `<>' includes that `""' includes get with 820no special options. `-I.' searches the compiler's current working 821directory for header files. That may or may not be the same as the 822directory containing the current file. 823 824 If you need to look for headers in a directory named `-', write 825`-I./-'. 826 827 There are several more ways to adjust the header search path. They 828are generally less useful. *Note Invocation::. 829 830 831File: cpp.info, Node: Once-Only Headers, Next: Alternatives to Wrapper #ifndef, Prev: Search Path, Up: Header Files 832 8332.4 Once-Only Headers 834===================== 835 836If a header file happens to be included twice, the compiler will process 837its contents twice. This is very likely to cause an error, e.g. when 838the compiler sees the same structure definition twice. Even if it does 839not, it will certainly waste time. 840 841 The standard way to prevent this is to enclose the entire real 842contents of the file in a conditional, like this: 843 844 /* File foo. */ 845 #ifndef FILE_FOO_SEEN 846 #define FILE_FOO_SEEN 847 848 THE ENTIRE FILE 849 850 #endif /* !FILE_FOO_SEEN */ 851 852 This construct is commonly known as a "wrapper #ifndef". When the 853header is included again, the conditional will be false, because 854`FILE_FOO_SEEN' is defined. The preprocessor will skip over the entire 855contents of the file, and the compiler will not see it twice. 856 857 CPP optimizes even further. It remembers when a header file has a 858wrapper `#ifndef'. If a subsequent `#include' specifies that header, 859and the macro in the `#ifndef' is still defined, it does not bother to 860rescan the file at all. 861 862 You can put comments outside the wrapper. They will not interfere 863with this optimization. 864 865 The macro `FILE_FOO_SEEN' is called the "controlling macro" or 866"guard macro". In a user header file, the macro name should not begin 867with `_'. In a system header file, it should begin with `__' to avoid 868conflicts with user programs. In any kind of header file, the macro 869name should contain the name of the file and some additional text, to 870avoid conflicts with other header files. 871 872 873File: cpp.info, Node: Alternatives to Wrapper #ifndef, Next: Computed Includes, Prev: Once-Only Headers, Up: Header Files 874 8752.5 Alternatives to Wrapper #ifndef 876=================================== 877 878CPP supports two more ways of indicating that a header file should be 879read only once. Neither one is as portable as a wrapper `#ifndef' and 880we recommend you do not use them in new programs, with the caveat that 881`#import' is standard practice in Objective-C. 882 883 CPP supports a variant of `#include' called `#import' which includes 884a file, but does so at most once. If you use `#import' instead of 885`#include', then you don't need the conditionals inside the header file 886to prevent multiple inclusion of the contents. `#import' is standard 887in Objective-C, but is considered a deprecated extension in C and C++. 888 889 `#import' is not a well designed feature. It requires the users of 890a header file to know that it should only be included once. It is much 891better for the header file's implementor to write the file so that users 892don't need to know this. Using a wrapper `#ifndef' accomplishes this 893goal. 894 895 In the present implementation, a single use of `#import' will 896prevent the file from ever being read again, by either `#import' or 897`#include'. You should not rely on this; do not use both `#import' and 898`#include' to refer to the same header file. 899 900 Another way to prevent a header file from being included more than 901once is with the `#pragma once' directive. If `#pragma once' is seen 902when scanning a header file, that file will never be read again, no 903matter what. 904 905 `#pragma once' does not have the problems that `#import' does, but 906it is not recognized by all preprocessors, so you cannot rely on it in 907a portable program. 908 909 910File: cpp.info, Node: Computed Includes, Next: Wrapper Headers, Prev: Alternatives to Wrapper #ifndef, Up: Header Files 911 9122.6 Computed Includes 913===================== 914 915Sometimes it is necessary to select one of several different header 916files to be included into your program. They might specify 917configuration parameters to be used on different sorts of operating 918systems, for instance. You could do this with a series of conditionals, 919 920 #if SYSTEM_1 921 # include "system_1.h" 922 #elif SYSTEM_2 923 # include "system_2.h" 924 #elif SYSTEM_3 925 ... 926 #endif 927 928 That rapidly becomes tedious. Instead, the preprocessor offers the 929ability to use a macro for the header name. This is called a "computed 930include". Instead of writing a header name as the direct argument of 931`#include', you simply put a macro name there instead: 932 933 #define SYSTEM_H "system_1.h" 934 ... 935 #include SYSTEM_H 936 937`SYSTEM_H' will be expanded, and the preprocessor will look for 938`system_1.h' as if the `#include' had been written that way originally. 939`SYSTEM_H' could be defined by your Makefile with a `-D' option. 940 941 You must be careful when you define the macro. `#define' saves 942tokens, not text. The preprocessor has no way of knowing that the macro 943will be used as the argument of `#include', so it generates ordinary 944tokens, not a header name. This is unlikely to cause problems if you 945use double-quote includes, which are close enough to string constants. 946If you use angle brackets, however, you may have trouble. 947 948 The syntax of a computed include is actually a bit more general than 949the above. If the first non-whitespace character after `#include' is 950not `"' or `<', then the entire line is macro-expanded like running 951text would be. 952 953 If the line expands to a single string constant, the contents of that 954string constant are the file to be included. CPP does not re-examine 955the string for embedded quotes, but neither does it process backslash 956escapes in the string. Therefore 957 958 #define HEADER "a\"b" 959 #include HEADER 960 961looks for a file named `a\"b'. CPP searches for the file according to 962the rules for double-quoted includes. 963 964 If the line expands to a token stream beginning with a `<' token and 965including a `>' token, then the tokens between the `<' and the first 966`>' are combined to form the filename to be included. Any whitespace 967between tokens is reduced to a single space; then any space after the 968initial `<' is retained, but a trailing space before the closing `>' is 969ignored. CPP searches for the file according to the rules for 970angle-bracket includes. 971 972 In either case, if there are any tokens on the line after the file 973name, an error occurs and the directive is not processed. It is also 974an error if the result of expansion does not match either of the two 975expected forms. 976 977 These rules are implementation-defined behavior according to the C 978standard. To minimize the risk of different compilers interpreting your 979computed includes differently, we recommend you use only a single 980object-like macro which expands to a string constant. This will also 981minimize confusion for people reading your program. 982 983 984File: cpp.info, Node: Wrapper Headers, Next: System Headers, Prev: Computed Includes, Up: Header Files 985 9862.7 Wrapper Headers 987=================== 988 989Sometimes it is necessary to adjust the contents of a system-provided 990header file without editing it directly. GCC's `fixincludes' operation 991does this, for example. One way to do that would be to create a new 992header file with the same name and insert it in the search path before 993the original header. That works fine as long as you're willing to 994replace the old header entirely. But what if you want to refer to the 995old header from the new one? 996 997 You cannot simply include the old header with `#include'. That will 998start from the beginning, and find your new header again. If your 999header is not protected from multiple inclusion (*note Once-Only 1000Headers::), it will recurse infinitely and cause a fatal error. 1001 1002 You could include the old header with an absolute pathname: 1003 #include "/usr/include/old-header.h" 1004 This works, but is not clean; should the system headers ever move, 1005you would have to edit the new headers to match. 1006 1007 There is no way to solve this problem within the C standard, but you 1008can use the GNU extension `#include_next'. It means, "Include the 1009_next_ file with this name". This directive works like `#include' 1010except in searching for the specified file: it starts searching the 1011list of header file directories _after_ the directory in which the 1012current file was found. 1013 1014 Suppose you specify `-I /usr/local/include', and the list of 1015directories to search also includes `/usr/include'; and suppose both 1016directories contain `signal.h'. Ordinary `#include <signal.h>' finds 1017the file under `/usr/local/include'. If that file contains 1018`#include_next <signal.h>', it starts searching after that directory, 1019and finds the file in `/usr/include'. 1020 1021 `#include_next' does not distinguish between `<FILE>' and `"FILE"' 1022inclusion, nor does it check that the file you specify has the same 1023name as the current file. It simply looks for the file named, starting 1024with the directory in the search path after the one where the current 1025file was found. 1026 1027 The use of `#include_next' can lead to great confusion. We 1028recommend it be used only when there is no other alternative. In 1029particular, it should not be used in the headers belonging to a specific 1030program; it should be used only to make global corrections along the 1031lines of `fixincludes'. 1032 1033 1034File: cpp.info, Node: System Headers, Prev: Wrapper Headers, Up: Header Files 1035 10362.8 System Headers 1037================== 1038 1039The header files declaring interfaces to the operating system and 1040runtime libraries often cannot be written in strictly conforming C. 1041Therefore, GCC gives code found in "system headers" special treatment. 1042All warnings, other than those generated by `#warning' (*note 1043Diagnostics::), are suppressed while GCC is processing a system header. 1044Macros defined in a system header are immune to a few warnings 1045wherever they are expanded. This immunity is granted on an ad-hoc 1046basis, when we find that a warning generates lots of false positives 1047because of code in macros defined in system headers. 1048 1049 Normally, only the headers found in specific directories are 1050considered system headers. These directories are determined when GCC 1051is compiled. There are, however, two ways to make normal headers into 1052system headers. 1053 1054 The `-isystem' command line option adds its argument to the list of 1055directories to search for headers, just like `-I'. Any headers found 1056in that directory will be considered system headers. 1057 1058 All directories named by `-isystem' are searched _after_ all 1059directories named by `-I', no matter what their order was on the 1060command line. If the same directory is named by both `-I' and 1061`-isystem', the `-I' option is ignored. GCC provides an informative 1062message when this occurs if `-v' is used. 1063 1064 There is also a directive, `#pragma GCC system_header', which tells 1065GCC to consider the rest of the current include file a system header, 1066no matter where it was found. Code that comes before the `#pragma' in 1067the file will not be affected. `#pragma GCC system_header' has no 1068effect in the primary source file. 1069 1070 On very old systems, some of the pre-defined system header 1071directories get even more special treatment. GNU C++ considers code in 1072headers found in those directories to be surrounded by an `extern "C"' 1073block. There is no way to request this behavior with a `#pragma', or 1074from the command line. 1075 1076 1077File: cpp.info, Node: Macros, Next: Conditionals, Prev: Header Files, Up: Top 1078 10793 Macros 1080******** 1081 1082A "macro" is a fragment of code which has been given a name. Whenever 1083the name is used, it is replaced by the contents of the macro. There 1084are two kinds of macros. They differ mostly in what they look like 1085when they are used. "Object-like" macros resemble data objects when 1086used, "function-like" macros resemble function calls. 1087 1088 You may define any valid identifier as a macro, even if it is a C 1089keyword. The preprocessor does not know anything about keywords. This 1090can be useful if you wish to hide a keyword such as `const' from an 1091older compiler that does not understand it. However, the preprocessor 1092operator `defined' (*note Defined::) can never be defined as a macro, 1093and C++'s named operators (*note C++ Named Operators::) cannot be 1094macros when you are compiling C++. 1095 1096* Menu: 1097 1098* Object-like Macros:: 1099* Function-like Macros:: 1100* Macro Arguments:: 1101* Stringification:: 1102* Concatenation:: 1103* Variadic Macros:: 1104* Predefined Macros:: 1105* Undefining and Redefining Macros:: 1106* Directives Within Macro Arguments:: 1107* Macro Pitfalls:: 1108 1109 1110File: cpp.info, Node: Object-like Macros, Next: Function-like Macros, Up: Macros 1111 11123.1 Object-like Macros 1113====================== 1114 1115An "object-like macro" is a simple identifier which will be replaced by 1116a code fragment. It is called object-like because it looks like a data 1117object in code that uses it. They are most commonly used to give 1118symbolic names to numeric constants. 1119 1120 You create macros with the `#define' directive. `#define' is 1121followed by the name of the macro and then the token sequence it should 1122be an abbreviation for, which is variously referred to as the macro's 1123"body", "expansion" or "replacement list". For example, 1124 1125 #define BUFFER_SIZE 1024 1126 1127defines a macro named `BUFFER_SIZE' as an abbreviation for the token 1128`1024'. If somewhere after this `#define' directive there comes a C 1129statement of the form 1130 1131 foo = (char *) malloc (BUFFER_SIZE); 1132 1133then the C preprocessor will recognize and "expand" the macro 1134`BUFFER_SIZE'. The C compiler will see the same tokens as it would if 1135you had written 1136 1137 foo = (char *) malloc (1024); 1138 1139 By convention, macro names are written in uppercase. Programs are 1140easier to read when it is possible to tell at a glance which names are 1141macros. 1142 1143 The macro's body ends at the end of the `#define' line. You may 1144continue the definition onto multiple lines, if necessary, using 1145backslash-newline. When the macro is expanded, however, it will all 1146come out on one line. For example, 1147 1148 #define NUMBERS 1, \ 1149 2, \ 1150 3 1151 int x[] = { NUMBERS }; 1152 ==> int x[] = { 1, 2, 3 }; 1153 1154The most common visible consequence of this is surprising line numbers 1155in error messages. 1156 1157 There is no restriction on what can go in a macro body provided it 1158decomposes into valid preprocessing tokens. Parentheses need not 1159balance, and the body need not resemble valid C code. (If it does not, 1160you may get error messages from the C compiler when you use the macro.) 1161 1162 The C preprocessor scans your program sequentially. Macro 1163definitions take effect at the place you write them. Therefore, the 1164following input to the C preprocessor 1165 1166 foo = X; 1167 #define X 4 1168 bar = X; 1169 1170produces 1171 1172 foo = X; 1173 bar = 4; 1174 1175 When the preprocessor expands a macro name, the macro's expansion 1176replaces the macro invocation, then the expansion is examined for more 1177macros to expand. For example, 1178 1179 #define TABLESIZE BUFSIZE 1180 #define BUFSIZE 1024 1181 TABLESIZE 1182 ==> BUFSIZE 1183 ==> 1024 1184 1185`TABLESIZE' is expanded first to produce `BUFSIZE', then that macro is 1186expanded to produce the final result, `1024'. 1187 1188 Notice that `BUFSIZE' was not defined when `TABLESIZE' was defined. 1189The `#define' for `TABLESIZE' uses exactly the expansion you 1190specify--in this case, `BUFSIZE'--and does not check to see whether it 1191too contains macro names. Only when you _use_ `TABLESIZE' is the 1192result of its expansion scanned for more macro names. 1193 1194 This makes a difference if you change the definition of `BUFSIZE' at 1195some point in the source file. `TABLESIZE', defined as shown, will 1196always expand using the definition of `BUFSIZE' that is currently in 1197effect: 1198 1199 #define BUFSIZE 1020 1200 #define TABLESIZE BUFSIZE 1201 #undef BUFSIZE 1202 #define BUFSIZE 37 1203 1204Now `TABLESIZE' expands (in two stages) to `37'. 1205 1206 If the expansion of a macro contains its own name, either directly or 1207via intermediate macros, it is not expanded again when the expansion is 1208examined for more macros. This prevents infinite recursion. *Note 1209Self-Referential Macros::, for the precise details. 1210 1211 1212File: cpp.info, Node: Function-like Macros, Next: Macro Arguments, Prev: Object-like Macros, Up: Macros 1213 12143.2 Function-like Macros 1215======================== 1216 1217You can also define macros whose use looks like a function call. These 1218are called "function-like macros". To define a function-like macro, 1219you use the same `#define' directive, but you put a pair of parentheses 1220immediately after the macro name. For example, 1221 1222 #define lang_init() c_init() 1223 lang_init() 1224 ==> c_init() 1225 1226 A function-like macro is only expanded if its name appears with a 1227pair of parentheses after it. If you write just the name, it is left 1228alone. This can be useful when you have a function and a macro of the 1229same name, and you wish to use the function sometimes. 1230 1231 extern void foo(void); 1232 #define foo() /* optimized inline version */ 1233 ... 1234 foo(); 1235 funcptr = foo; 1236 1237 Here the call to `foo()' will use the macro, but the function 1238pointer will get the address of the real function. If the macro were to 1239be expanded, it would cause a syntax error. 1240 1241 If you put spaces between the macro name and the parentheses in the 1242macro definition, that does not define a function-like macro, it defines 1243an object-like macro whose expansion happens to begin with a pair of 1244parentheses. 1245 1246 #define lang_init () c_init() 1247 lang_init() 1248 ==> () c_init()() 1249 1250 The first two pairs of parentheses in this expansion come from the 1251macro. The third is the pair that was originally after the macro 1252invocation. Since `lang_init' is an object-like macro, it does not 1253consume those parentheses. 1254 1255 1256File: cpp.info, Node: Macro Arguments, Next: Stringification, Prev: Function-like Macros, Up: Macros 1257 12583.3 Macro Arguments 1259=================== 1260 1261Function-like macros can take "arguments", just like true functions. 1262To define a macro that uses arguments, you insert "parameters" between 1263the pair of parentheses in the macro definition that make the macro 1264function-like. The parameters must be valid C identifiers, separated 1265by commas and optionally whitespace. 1266 1267 To invoke a macro that takes arguments, you write the name of the 1268macro followed by a list of "actual arguments" in parentheses, separated 1269by commas. The invocation of the macro need not be restricted to a 1270single logical line--it can cross as many lines in the source file as 1271you wish. The number of arguments you give must match the number of 1272parameters in the macro definition. When the macro is expanded, each 1273use of a parameter in its body is replaced by the tokens of the 1274corresponding argument. (You need not use all of the parameters in the 1275macro body.) 1276 1277 As an example, here is a macro that computes the minimum of two 1278numeric values, as it is defined in many C programs, and some uses. 1279 1280 #define min(X, Y) ((X) < (Y) ? (X) : (Y)) 1281 x = min(a, b); ==> x = ((a) < (b) ? (a) : (b)); 1282 y = min(1, 2); ==> y = ((1) < (2) ? (1) : (2)); 1283 z = min(a + 28, *p); ==> z = ((a + 28) < (*p) ? (a + 28) : (*p)); 1284 1285(In this small example you can already see several of the dangers of 1286macro arguments. *Note Macro Pitfalls::, for detailed explanations.) 1287 1288 Leading and trailing whitespace in each argument is dropped, and all 1289whitespace between the tokens of an argument is reduced to a single 1290space. Parentheses within each argument must balance; a comma within 1291such parentheses does not end the argument. However, there is no 1292requirement for square brackets or braces to balance, and they do not 1293prevent a comma from separating arguments. Thus, 1294 1295 macro (array[x = y, x + 1]) 1296 1297passes two arguments to `macro': `array[x = y' and `x + 1]'. If you 1298want to supply `array[x = y, x + 1]' as an argument, you can write it 1299as `array[(x = y, x + 1)]', which is equivalent C code. 1300 1301 All arguments to a macro are completely macro-expanded before they 1302are substituted into the macro body. After substitution, the complete 1303text is scanned again for macros to expand, including the arguments. 1304This rule may seem strange, but it is carefully designed so you need 1305not worry about whether any function call is actually a macro 1306invocation. You can run into trouble if you try to be too clever, 1307though. *Note Argument Prescan::, for detailed discussion. 1308 1309 For example, `min (min (a, b), c)' is first expanded to 1310 1311 min (((a) < (b) ? (a) : (b)), (c)) 1312 1313and then to 1314 1315 ((((a) < (b) ? (a) : (b))) < (c) 1316 ? (((a) < (b) ? (a) : (b))) 1317 : (c)) 1318 1319(Line breaks shown here for clarity would not actually be generated.) 1320 1321 You can leave macro arguments empty; this is not an error to the 1322preprocessor (but many macros will then expand to invalid code). You 1323cannot leave out arguments entirely; if a macro takes two arguments, 1324there must be exactly one comma at the top level of its argument list. 1325Here are some silly examples using `min': 1326 1327 min(, b) ==> (( ) < (b) ? ( ) : (b)) 1328 min(a, ) ==> ((a ) < ( ) ? (a ) : ( )) 1329 min(,) ==> (( ) < ( ) ? ( ) : ( )) 1330 min((,),) ==> (((,)) < ( ) ? ((,)) : ( )) 1331 1332 min() error--> macro "min" requires 2 arguments, but only 1 given 1333 min(,,) error--> macro "min" passed 3 arguments, but takes just 2 1334 1335 Whitespace is not a preprocessing token, so if a macro `foo' takes 1336one argument, `foo ()' and `foo ( )' both supply it an empty argument. 1337Previous GNU preprocessor implementations and documentation were 1338incorrect on this point, insisting that a function-like macro that 1339takes a single argument be passed a space if an empty argument was 1340required. 1341 1342 Macro parameters appearing inside string literals are not replaced by 1343their corresponding actual arguments. 1344 1345 #define foo(x) x, "x" 1346 foo(bar) ==> bar, "x" 1347 1348 1349File: cpp.info, Node: Stringification, Next: Concatenation, Prev: Macro Arguments, Up: Macros 1350 13513.4 Stringification 1352=================== 1353 1354Sometimes you may want to convert a macro argument into a string 1355constant. Parameters are not replaced inside string constants, but you 1356can use the `#' preprocessing operator instead. When a macro parameter 1357is used with a leading `#', the preprocessor replaces it with the 1358literal text of the actual argument, converted to a string constant. 1359Unlike normal parameter replacement, the argument is not macro-expanded 1360first. This is called "stringification". 1361 1362 There is no way to combine an argument with surrounding text and 1363stringify it all together. Instead, you can write a series of adjacent 1364string constants and stringified arguments. The preprocessor will 1365replace the stringified arguments with string constants. The C 1366compiler will then combine all the adjacent string constants into one 1367long string. 1368 1369 Here is an example of a macro definition that uses stringification: 1370 1371 #define WARN_IF(EXP) \ 1372 do { if (EXP) \ 1373 fprintf (stderr, "Warning: " #EXP "\n"); } \ 1374 while (0) 1375 WARN_IF (x == 0); 1376 ==> do { if (x == 0) 1377 fprintf (stderr, "Warning: " "x == 0" "\n"); } while (0); 1378 1379The argument for `EXP' is substituted once, as-is, into the `if' 1380statement, and once, stringified, into the argument to `fprintf'. If 1381`x' were a macro, it would be expanded in the `if' statement, but not 1382in the string. 1383 1384 The `do' and `while (0)' are a kludge to make it possible to write 1385`WARN_IF (ARG);', which the resemblance of `WARN_IF' to a function 1386would make C programmers want to do; see *Note Swallowing the 1387Semicolon::. 1388 1389 Stringification in C involves more than putting double-quote 1390characters around the fragment. The preprocessor backslash-escapes the 1391quotes surrounding embedded string constants, and all backslashes 1392within string and character constants, in order to get a valid C string 1393constant with the proper contents. Thus, stringifying `p = "foo\n";' 1394results in "p = \"foo\\n\";". However, backslashes that are not inside 1395string or character constants are not duplicated: `\n' by itself 1396stringifies to "\n". 1397 1398 All leading and trailing whitespace in text being stringified is 1399ignored. Any sequence of whitespace in the middle of the text is 1400converted to a single space in the stringified result. Comments are 1401replaced by whitespace long before stringification happens, so they 1402never appear in stringified text. 1403 1404 There is no way to convert a macro argument into a character 1405constant. 1406 1407 If you want to stringify the result of expansion of a macro argument, 1408you have to use two levels of macros. 1409 1410 #define xstr(s) str(s) 1411 #define str(s) #s 1412 #define foo 4 1413 str (foo) 1414 ==> "foo" 1415 xstr (foo) 1416 ==> xstr (4) 1417 ==> str (4) 1418 ==> "4" 1419 1420 `s' is stringified when it is used in `str', so it is not 1421macro-expanded first. But `s' is an ordinary argument to `xstr', so it 1422is completely macro-expanded before `xstr' itself is expanded (*note 1423Argument Prescan::). Therefore, by the time `str' gets to its 1424argument, it has already been macro-expanded. 1425 1426 1427File: cpp.info, Node: Concatenation, Next: Variadic Macros, Prev: Stringification, Up: Macros 1428 14293.5 Concatenation 1430================= 1431 1432It is often useful to merge two tokens into one while expanding macros. 1433This is called "token pasting" or "token concatenation". The `##' 1434preprocessing operator performs token pasting. When a macro is 1435expanded, the two tokens on either side of each `##' operator are 1436combined into a single token, which then replaces the `##' and the two 1437original tokens in the macro expansion. Usually both will be 1438identifiers, or one will be an identifier and the other a preprocessing 1439number. When pasted, they make a longer identifier. This isn't the 1440only valid case. It is also possible to concatenate two numbers (or a 1441number and a name, such as `1.5' and `e3') into a number. Also, 1442multi-character operators such as `+=' can be formed by token pasting. 1443 1444 However, two tokens that don't together form a valid token cannot be 1445pasted together. For example, you cannot concatenate `x' with `+' in 1446either order. If you try, the preprocessor issues a warning and emits 1447the two tokens. Whether it puts white space between the tokens is 1448undefined. It is common to find unnecessary uses of `##' in complex 1449macros. If you get this warning, it is likely that you can simply 1450remove the `##'. 1451 1452 Both the tokens combined by `##' could come from the macro body, but 1453you could just as well write them as one token in the first place. 1454Token pasting is most useful when one or both of the tokens comes from a 1455macro argument. If either of the tokens next to an `##' is a parameter 1456name, it is replaced by its actual argument before `##' executes. As 1457with stringification, the actual argument is not macro-expanded first. 1458If the argument is empty, that `##' has no effect. 1459 1460 Keep in mind that the C preprocessor converts comments to whitespace 1461before macros are even considered. Therefore, you cannot create a 1462comment by concatenating `/' and `*'. You can put as much whitespace 1463between `##' and its operands as you like, including comments, and you 1464can put comments in arguments that will be concatenated. However, it 1465is an error if `##' appears at either end of a macro body. 1466 1467 Consider a C program that interprets named commands. There probably 1468needs to be a table of commands, perhaps an array of structures declared 1469as follows: 1470 1471 struct command 1472 { 1473 char *name; 1474 void (*function) (void); 1475 }; 1476 1477 struct command commands[] = 1478 { 1479 { "quit", quit_command }, 1480 { "help", help_command }, 1481 ... 1482 }; 1483 1484 It would be cleaner not to have to give each command name twice, 1485once in the string constant and once in the function name. A macro 1486which takes the name of a command as an argument can make this 1487unnecessary. The string constant can be created with stringification, 1488and the function name by concatenating the argument with `_command'. 1489Here is how it is done: 1490 1491 #define COMMAND(NAME) { #NAME, NAME ## _command } 1492 1493 struct command commands[] = 1494 { 1495 COMMAND (quit), 1496 COMMAND (help), 1497 ... 1498 }; 1499 1500 1501File: cpp.info, Node: Variadic Macros, Next: Predefined Macros, Prev: Concatenation, Up: Macros 1502 15033.6 Variadic Macros 1504=================== 1505 1506A macro can be declared to accept a variable number of arguments much as 1507a function can. The syntax for defining the macro is similar to that of 1508a function. Here is an example: 1509 1510 #define eprintf(...) fprintf (stderr, __VA_ARGS__) 1511 1512 This kind of macro is called "variadic". When the macro is invoked, 1513all the tokens in its argument list after the last named argument (this 1514macro has none), including any commas, become the "variable argument". 1515This sequence of tokens replaces the identifier `__VA_ARGS__' in the 1516macro body wherever it appears. Thus, we have this expansion: 1517 1518 eprintf ("%s:%d: ", input_file, lineno) 1519 ==> fprintf (stderr, "%s:%d: ", input_file, lineno) 1520 1521 The variable argument is completely macro-expanded before it is 1522inserted into the macro expansion, just like an ordinary argument. You 1523may use the `#' and `##' operators to stringify the variable argument 1524or to paste its leading or trailing token with another token. (But see 1525below for an important special case for `##'.) 1526 1527 If your macro is complicated, you may want a more descriptive name 1528for the variable argument than `__VA_ARGS__'. CPP permits this, as an 1529extension. You may write an argument name immediately before the 1530`...'; that name is used for the variable argument. The `eprintf' 1531macro above could be written 1532 1533 #define eprintf(args...) fprintf (stderr, args) 1534 1535using this extension. You cannot use `__VA_ARGS__' and this extension 1536in the same macro. 1537 1538 You can have named arguments as well as variable arguments in a 1539variadic macro. We could define `eprintf' like this, instead: 1540 1541 #define eprintf(format, ...) fprintf (stderr, format, __VA_ARGS__) 1542 1543This formulation looks more descriptive, but unfortunately it is less 1544flexible: you must now supply at least one argument after the format 1545string. In standard C, you cannot omit the comma separating the named 1546argument from the variable arguments. Furthermore, if you leave the 1547variable argument empty, you will get a syntax error, because there 1548will be an extra comma after the format string. 1549 1550 eprintf("success!\n", ); 1551 ==> fprintf(stderr, "success!\n", ); 1552 1553 GNU CPP has a pair of extensions which deal with this problem. 1554First, you are allowed to leave the variable argument out entirely: 1555 1556 eprintf ("success!\n") 1557 ==> fprintf(stderr, "success!\n", ); 1558 1559Second, the `##' token paste operator has a special meaning when placed 1560between a comma and a variable argument. If you write 1561 1562 #define eprintf(format, ...) fprintf (stderr, format, ##__VA_ARGS__) 1563 1564and the variable argument is left out when the `eprintf' macro is used, 1565then the comma before the `##' will be deleted. This does _not_ happen 1566if you pass an empty argument, nor does it happen if the token 1567preceding `##' is anything other than a comma. 1568 1569 eprintf ("success!\n") 1570 ==> fprintf(stderr, "success!\n"); 1571 1572The above explanation is ambiguous about the case where the only macro 1573parameter is a variable arguments parameter, as it is meaningless to 1574try to distinguish whether no argument at all is an empty argument or a 1575missing argument. In this case the C99 standard is clear that the 1576comma must remain, however the existing GCC extension used to swallow 1577the comma. So CPP retains the comma when conforming to a specific C 1578standard, and drops it otherwise. 1579 1580 C99 mandates that the only place the identifier `__VA_ARGS__' can 1581appear is in the replacement list of a variadic macro. It may not be 1582used as a macro name, macro argument name, or within a different type 1583of macro. It may also be forbidden in open text; the standard is 1584ambiguous. We recommend you avoid using it except for its defined 1585purpose. 1586 1587 Variadic macros are a new feature in C99. GNU CPP has supported them 1588for a long time, but only with a named variable argument (`args...', 1589not `...' and `__VA_ARGS__'). If you are concerned with portability to 1590previous versions of GCC, you should use only named variable arguments. 1591On the other hand, if you are concerned with portability to other 1592conforming implementations of C99, you should use only `__VA_ARGS__'. 1593 1594 Previous versions of CPP implemented the comma-deletion extension 1595much more generally. We have restricted it in this release to minimize 1596the differences from C99. To get the same effect with both this and 1597previous versions of GCC, the token preceding the special `##' must be 1598a comma, and there must be white space between that comma and whatever 1599comes immediately before it: 1600 1601 #define eprintf(format, args...) fprintf (stderr, format , ##args) 1602 1603*Note Differences from previous versions::, for the gory details. 1604 1605 1606File: cpp.info, Node: Predefined Macros, Next: Undefining and Redefining Macros, Prev: Variadic Macros, Up: Macros 1607 16083.7 Predefined Macros 1609===================== 1610 1611Several object-like macros are predefined; you use them without 1612supplying their definitions. They fall into three classes: standard, 1613common, and system-specific. 1614 1615 In C++, there is a fourth category, the named operators. They act 1616like predefined macros, but you cannot undefine them. 1617 1618* Menu: 1619 1620* Standard Predefined Macros:: 1621* Common Predefined Macros:: 1622* System-specific Predefined Macros:: 1623* C++ Named Operators:: 1624 1625 1626File: cpp.info, Node: Standard Predefined Macros, Next: Common Predefined Macros, Up: Predefined Macros 1627 16283.7.1 Standard Predefined Macros 1629-------------------------------- 1630 1631The standard predefined macros are specified by the relevant language 1632standards, so they are available with all compilers that implement 1633those standards. Older compilers may not provide all of them. Their 1634names all start with double underscores. 1635 1636`__FILE__' 1637 This macro expands to the name of the current input file, in the 1638 form of a C string constant. This is the path by which the 1639 preprocessor opened the file, not the short name specified in 1640 `#include' or as the input file name argument. For example, 1641 `"/usr/local/include/myheader.h"' is a possible expansion of this 1642 macro. 1643 1644`__LINE__' 1645 This macro expands to the current input line number, in the form 1646 of a decimal integer constant. While we call it a predefined 1647 macro, it's a pretty strange macro, since its "definition" changes 1648 with each new line of source code. 1649 1650 `__FILE__' and `__LINE__' are useful in generating an error message 1651to report an inconsistency detected by the program; the message can 1652state the source line at which the inconsistency was detected. For 1653example, 1654 1655 fprintf (stderr, "Internal error: " 1656 "negative string length " 1657 "%d at %s, line %d.", 1658 length, __FILE__, __LINE__); 1659 1660 An `#include' directive changes the expansions of `__FILE__' and 1661`__LINE__' to correspond to the included file. At the end of that 1662file, when processing resumes on the input file that contained the 1663`#include' directive, the expansions of `__FILE__' and `__LINE__' 1664revert to the values they had before the `#include' (but `__LINE__' is 1665then incremented by one as processing moves to the line after the 1666`#include'). 1667 1668 A `#line' directive changes `__LINE__', and may change `__FILE__' as 1669well. *Note Line Control::. 1670 1671 C99 introduces `__func__', and GCC has provided `__FUNCTION__' for a 1672long time. Both of these are strings containing the name of the 1673current function (there are slight semantic differences; see the GCC 1674manual). Neither of them is a macro; the preprocessor does not know the 1675name of the current function. They tend to be useful in conjunction 1676with `__FILE__' and `__LINE__', though. 1677 1678`__DATE__' 1679 This macro expands to a string constant that describes the date on 1680 which the preprocessor is being run. The string constant contains 1681 eleven characters and looks like `"Feb 12 1996"'. If the day of 1682 the month is less than 10, it is padded with a space on the left. 1683 1684 If GCC cannot determine the current date, it will emit a warning 1685 message (once per compilation) and `__DATE__' will expand to 1686 `"??? ?? ????"'. 1687 1688`__TIME__' 1689 This macro expands to a string constant that describes the time at 1690 which the preprocessor is being run. The string constant contains 1691 eight characters and looks like `"23:59:01"'. 1692 1693 If GCC cannot determine the current time, it will emit a warning 1694 message (once per compilation) and `__TIME__' will expand to 1695 `"??:??:??"'. 1696 1697`__STDC__' 1698 In normal operation, this macro expands to the constant 1, to 1699 signify that this compiler conforms to ISO Standard C. If GNU CPP 1700 is used with a compiler other than GCC, this is not necessarily 1701 true; however, the preprocessor always conforms to the standard 1702 unless the `-traditional-cpp' option is used. 1703 1704 This macro is not defined if the `-traditional-cpp' option is used. 1705 1706 On some hosts, the system compiler uses a different convention, 1707 where `__STDC__' is normally 0, but is 1 if the user specifies 1708 strict conformance to the C Standard. CPP follows the host 1709 convention when processing system header files, but when 1710 processing user files `__STDC__' is always 1. This has been 1711 reported to cause problems; for instance, some versions of Solaris 1712 provide X Windows headers that expect `__STDC__' to be either 1713 undefined or 1. *Note Invocation::. 1714 1715`__STDC_VERSION__' 1716 This macro expands to the C Standard's version number, a long 1717 integer constant of the form `YYYYMML' where YYYY and MM are the 1718 year and month of the Standard version. This signifies which 1719 version of the C Standard the compiler conforms to. Like 1720 `__STDC__', this is not necessarily accurate for the entire 1721 implementation, unless GNU CPP is being used with GCC. 1722 1723 The value `199409L' signifies the 1989 C standard as amended in 1724 1994, which is the current default; the value `199901L' signifies 1725 the 1999 revision of the C standard. Support for the 1999 1726 revision is not yet complete. 1727 1728 This macro is not defined if the `-traditional-cpp' option is 1729 used, nor when compiling C++ or Objective-C. 1730 1731`__STDC_HOSTED__' 1732 This macro is defined, with value 1, if the compiler's target is a 1733 "hosted environment". A hosted environment has the complete 1734 facilities of the standard C library available. 1735 1736`__cplusplus' 1737 This macro is defined when the C++ compiler is in use. You can use 1738 `__cplusplus' to test whether a header is compiled by a C compiler 1739 or a C++ compiler. This macro is similar to `__STDC_VERSION__', in 1740 that it expands to a version number. A fully conforming 1741 implementation of the 1998 C++ standard will define this macro to 1742 `199711L'. The GNU C++ compiler is not yet fully conforming, so 1743 it uses `1' instead. It is hoped to complete the implementation 1744 of standard C++ in the near future. 1745 1746`__OBJC__' 1747 This macro is defined, with value 1, when the Objective-C compiler 1748 is in use. You can use `__OBJC__' to test whether a header is 1749 compiled by a C compiler or an Objective-C compiler. 1750 1751`__ASSEMBLER__' 1752 This macro is defined with value 1 when preprocessing assembly 1753 language. 1754 1755 1756 1757File: cpp.info, Node: Common Predefined Macros, Next: System-specific Predefined Macros, Prev: Standard Predefined Macros, Up: Predefined Macros 1758 17593.7.2 Common Predefined Macros 1760------------------------------ 1761 1762The common predefined macros are GNU C extensions. They are available 1763with the same meanings regardless of the machine or operating system on 1764which you are using GNU C or GNU Fortran. Their names all start with 1765double underscores. 1766 1767`__COUNTER__' 1768 This macro expands to sequential integral values starting from 0. 1769 In conjunction with the `##' operator, this provides a convenient 1770 means to generate unique identifiers. Care must be taken to 1771 ensure that `__COUNTER__' is not expanded prior to inclusion of 1772 precompiled headers which use it. Otherwise, the precompiled 1773 headers will not be used. 1774 1775`__GFORTRAN__' 1776 The GNU Fortran compiler defines this. 1777 1778`__GNUC__' 1779`__GNUC_MINOR__' 1780`__GNUC_PATCHLEVEL__' 1781 These macros are defined by all GNU compilers that use the C 1782 preprocessor: C, C++, Objective-C and Fortran. Their values are 1783 the major version, minor version, and patch level of the compiler, 1784 as integer constants. For example, GCC 3.2.1 will define 1785 `__GNUC__' to 3, `__GNUC_MINOR__' to 2, and `__GNUC_PATCHLEVEL__' 1786 to 1. These macros are also defined if you invoke the 1787 preprocessor directly. 1788 1789 `__GNUC_PATCHLEVEL__' is new to GCC 3.0; it is also present in the 1790 widely-used development snapshots leading up to 3.0 (which identify 1791 themselves as GCC 2.96 or 2.97, depending on which snapshot you 1792 have). 1793 1794 If all you need to know is whether or not your program is being 1795 compiled by GCC, or a non-GCC compiler that claims to accept the 1796 GNU C dialects, you can simply test `__GNUC__'. If you need to 1797 write code which depends on a specific version, you must be more 1798 careful. Each time the minor version is increased, the patch 1799 level is reset to zero; each time the major version is increased 1800 (which happens rarely), the minor version and patch level are 1801 reset. If you wish to use the predefined macros directly in the 1802 conditional, you will need to write it like this: 1803 1804 /* Test for GCC > 3.2.0 */ 1805 #if __GNUC__ > 3 || \ 1806 (__GNUC__ == 3 && (__GNUC_MINOR__ > 2 || \ 1807 (__GNUC_MINOR__ == 2 && \ 1808 __GNUC_PATCHLEVEL__ > 0)) 1809 1810 Another approach is to use the predefined macros to calculate a 1811 single number, then compare that against a threshold: 1812 1813 #define GCC_VERSION (__GNUC__ * 10000 \ 1814 + __GNUC_MINOR__ * 100 \ 1815 + __GNUC_PATCHLEVEL__) 1816 ... 1817 /* Test for GCC > 3.2.0 */ 1818 #if GCC_VERSION > 30200 1819 1820 Many people find this form easier to understand. 1821 1822`__GNUG__' 1823 The GNU C++ compiler defines this. Testing it is equivalent to 1824 testing `(__GNUC__ && __cplusplus)'. 1825 1826`__STRICT_ANSI__' 1827 GCC defines this macro if and only if the `-ansi' switch, or a 1828 `-std' switch specifying strict conformance to some version of ISO 1829 C, was specified when GCC was invoked. It is defined to `1'. 1830 This macro exists primarily to direct GNU libc's header files to 1831 restrict their definitions to the minimal set found in the 1989 C 1832 standard. 1833 1834`__BASE_FILE__' 1835 This macro expands to the name of the main input file, in the form 1836 of a C string constant. This is the source file that was specified 1837 on the command line of the preprocessor or C compiler. 1838 1839`__INCLUDE_LEVEL__' 1840 This macro expands to a decimal integer constant that represents 1841 the depth of nesting in include files. The value of this macro is 1842 incremented on every `#include' directive and decremented at the 1843 end of every included file. It starts out at 0, its value within 1844 the base file specified on the command line. 1845 1846`__ELF__' 1847 This macro is defined if the target uses the ELF object format. 1848 1849`__VERSION__' 1850 This macro expands to a string constant which describes the 1851 version of the compiler in use. You should not rely on its 1852 contents having any particular form, but it can be counted on to 1853 contain at least the release number. 1854 1855`__OPTIMIZE__' 1856`__OPTIMIZE_SIZE__' 1857`__NO_INLINE__' 1858 These macros describe the compilation mode. `__OPTIMIZE__' is 1859 defined in all optimizing compilations. `__OPTIMIZE_SIZE__' is 1860 defined if the compiler is optimizing for size, not speed. 1861 `__NO_INLINE__' is defined if no functions will be inlined into 1862 their callers (when not optimizing, or when inlining has been 1863 specifically disabled by `-fno-inline'). 1864 1865 These macros cause certain GNU header files to provide optimized 1866 definitions, using macros or inline functions, of system library 1867 functions. You should not use these macros in any way unless you 1868 make sure that programs will execute with the same effect whether 1869 or not they are defined. If they are defined, their value is 1. 1870 1871`__GNUC_GNU_INLINE__' 1872 GCC defines this macro if functions declared `inline' will be 1873 handled in GCC's traditional gnu90 mode. Object files will contain 1874 externally visible definitions of all functions declared `inline' 1875 without `extern' or `static'. They will not contain any 1876 definitions of any functions declared `extern inline'. 1877 1878`__GNUC_STDC_INLINE__' 1879 GCC defines this macro if functions declared `inline' will be 1880 handled according to the ISO C99 standard. Object files will 1881 contain externally visible definitions of all functions declared 1882 `extern inline'. They will not contain definitions of any 1883 functions declared `inline' without `extern'. 1884 1885 If this macro is defined, GCC supports the `gnu_inline' function 1886 attribute as a way to always get the gnu90 behavior. Support for 1887 this and `__GNUC_GNU_INLINE__' was added in GCC 4.1.3. If neither 1888 macro is defined, an older version of GCC is being used: `inline' 1889 functions will be compiled in gnu90 mode, and the `gnu_inline' 1890 function attribute will not be recognized. 1891 1892`__CHAR_UNSIGNED__' 1893 GCC defines this macro if and only if the data type `char' is 1894 unsigned on the target machine. It exists to cause the standard 1895 header file `limits.h' to work correctly. You should not use this 1896 macro yourself; instead, refer to the standard macros defined in 1897 `limits.h'. 1898 1899`__WCHAR_UNSIGNED__' 1900 Like `__CHAR_UNSIGNED__', this macro is defined if and only if the 1901 data type `wchar_t' is unsigned and the front-end is in C++ mode. 1902 1903`__REGISTER_PREFIX__' 1904 This macro expands to a single token (not a string constant) which 1905 is the prefix applied to CPU register names in assembly language 1906 for this target. You can use it to write assembly that is usable 1907 in multiple environments. For example, in the `m68k-aout' 1908 environment it expands to nothing, but in the `m68k-coff' 1909 environment it expands to a single `%'. 1910 1911`__USER_LABEL_PREFIX__' 1912 This macro expands to a single token which is the prefix applied to 1913 user labels (symbols visible to C code) in assembly. For example, 1914 in the `m68k-aout' environment it expands to an `_', but in the 1915 `m68k-coff' environment it expands to nothing. 1916 1917 This macro will have the correct definition even if 1918 `-f(no-)underscores' is in use, but it will not be correct if 1919 target-specific options that adjust this prefix are used (e.g. the 1920 OSF/rose `-mno-underscores' option). 1921 1922`__SIZE_TYPE__' 1923`__PTRDIFF_TYPE__' 1924`__WCHAR_TYPE__' 1925`__WINT_TYPE__' 1926`__INTMAX_TYPE__' 1927`__UINTMAX_TYPE__' 1928`__SIG_ATOMIC_TYPE__' 1929`__INT8_TYPE__' 1930`__INT16_TYPE__' 1931`__INT32_TYPE__' 1932`__INT64_TYPE__' 1933`__UINT8_TYPE__' 1934`__UINT16_TYPE__' 1935`__UINT32_TYPE__' 1936`__UINT64_TYPE__' 1937`__INT_LEAST8_TYPE__' 1938`__INT_LEAST16_TYPE__' 1939`__INT_LEAST32_TYPE__' 1940`__INT_LEAST64_TYPE__' 1941`__UINT_LEAST8_TYPE__' 1942`__UINT_LEAST16_TYPE__' 1943`__UINT_LEAST32_TYPE__' 1944`__UINT_LEAST64_TYPE__' 1945`__INT_FAST8_TYPE__' 1946`__INT_FAST16_TYPE__' 1947`__INT_FAST32_TYPE__' 1948`__INT_FAST64_TYPE__' 1949`__UINT_FAST8_TYPE__' 1950`__UINT_FAST16_TYPE__' 1951`__UINT_FAST32_TYPE__' 1952`__UINT_FAST64_TYPE__' 1953`__INTPTR_TYPE__' 1954`__UINTPTR_TYPE__' 1955 These macros are defined to the correct underlying types for the 1956 `size_t', `ptrdiff_t', `wchar_t', `wint_t', `intmax_t', 1957 `uintmax_t', `sig_atomic_t', `int8_t', `int16_t', `int32_t', 1958 `int64_t', `uint8_t', `uint16_t', `uint32_t', `uint64_t', 1959 `int_least8_t', `int_least16_t', `int_least32_t', `int_least64_t', 1960 `uint_least8_t', `uint_least16_t', `uint_least32_t', 1961 `uint_least64_t', `int_fast8_t', `int_fast16_t', `int_fast32_t', 1962 `int_fast64_t', `uint_fast8_t', `uint_fast16_t', `uint_fast32_t', 1963 `uint_fast64_t', `intptr_t', and `uintptr_t' typedefs, 1964 respectively. They exist to make the standard header files 1965 `stddef.h', `stdint.h', and `wchar.h' work correctly. You should 1966 not use these macros directly; instead, include the appropriate 1967 headers and use the typedefs. Some of these macros may not be 1968 defined on particular systems if GCC does not provide a `stdint.h' 1969 header on those systems. 1970 1971`__CHAR_BIT__' 1972 Defined to the number of bits used in the representation of the 1973 `char' data type. It exists to make the standard header given 1974 numerical limits work correctly. You should not use this macro 1975 directly; instead, include the appropriate headers. 1976 1977`__SCHAR_MAX__' 1978`__WCHAR_MAX__' 1979`__SHRT_MAX__' 1980`__INT_MAX__' 1981`__LONG_MAX__' 1982`__LONG_LONG_MAX__' 1983`__WINT_MAX__' 1984`__SIZE_MAX__' 1985`__PTRDIFF_MAX__' 1986`__INTMAX_MAX__' 1987`__UINTMAX_MAX__' 1988`__SIG_ATOMIC_MAX__' 1989`__INT8_MAX__' 1990`__INT16_MAX__' 1991`__INT32_MAX__' 1992`__INT64_MAX__' 1993`__UINT8_MAX__' 1994`__UINT16_MAX__' 1995`__UINT32_MAX__' 1996`__UINT64_MAX__' 1997`__INT_LEAST8_MAX__' 1998`__INT_LEAST16_MAX__' 1999`__INT_LEAST32_MAX__' 2000`__INT_LEAST64_MAX__' 2001`__UINT_LEAST8_MAX__' 2002`__UINT_LEAST16_MAX__' 2003`__UINT_LEAST32_MAX__' 2004`__UINT_LEAST64_MAX__' 2005`__INT_FAST8_MAX__' 2006`__INT_FAST16_MAX__' 2007`__INT_FAST32_MAX__' 2008`__INT_FAST64_MAX__' 2009`__UINT_FAST8_MAX__' 2010`__UINT_FAST16_MAX__' 2011`__UINT_FAST32_MAX__' 2012`__UINT_FAST64_MAX__' 2013`__INTPTR_MAX__' 2014`__UINTPTR_MAX__' 2015`__WCHAR_MIN__' 2016`__WINT_MIN__' 2017`__SIG_ATOMIC_MIN__' 2018 Defined to the maximum value of the `signed char', `wchar_t', 2019 `signed short', `signed int', `signed long', `signed long long', 2020 `wint_t', `size_t', `ptrdiff_t', `intmax_t', `uintmax_t', 2021 `sig_atomic_t', `int8_t', `int16_t', `int32_t', `int64_t', 2022 `uint8_t', `uint16_t', `uint32_t', `uint64_t', `int_least8_t', 2023 `int_least16_t', `int_least32_t', `int_least64_t', 2024 `uint_least8_t', `uint_least16_t', `uint_least32_t', 2025 `uint_least64_t', `int_fast8_t', `int_fast16_t', `int_fast32_t', 2026 `int_fast64_t', `uint_fast8_t', `uint_fast16_t', `uint_fast32_t', 2027 `uint_fast64_t', `intptr_t', and `uintptr_t' types and to the 2028 minimum value of the `wchar_t', `wint_t', and `sig_atomic_t' types 2029 respectively. They exist to make the standard header given 2030 numerical limits work correctly. You should not use these macros 2031 directly; instead, include the appropriate headers. Some of these 2032 macros may not be defined on particular systems if GCC does not 2033 provide a `stdint.h' header on those systems. 2034 2035`__INT8_C' 2036`__INT16_C' 2037`__INT32_C' 2038`__INT64_C' 2039`__UINT8_C' 2040`__UINT16_C' 2041`__UINT32_C' 2042`__UINT64_C' 2043`__INTMAX_C' 2044`__UINTMAX_C' 2045 Defined to implementations of the standard `stdint.h' macros with 2046 the same names without the leading `__'. They exist the make the 2047 implementation of that header work correctly. You should not use 2048 these macros directly; instead, include the appropriate headers. 2049 Some of these macros may not be defined on particular systems if 2050 GCC does not provide a `stdint.h' header on those systems. 2051 2052`__SIZEOF_INT__' 2053`__SIZEOF_LONG__' 2054`__SIZEOF_LONG_LONG__' 2055`__SIZEOF_SHORT__' 2056`__SIZEOF_POINTER__' 2057`__SIZEOF_FLOAT__' 2058`__SIZEOF_DOUBLE__' 2059`__SIZEOF_LONG_DOUBLE__' 2060`__SIZEOF_SIZE_T__' 2061`__SIZEOF_WCHAR_T__' 2062`__SIZEOF_WINT_T__' 2063`__SIZEOF_PTRDIFF_T__' 2064 Defined to the number of bytes of the C standard data types: `int', 2065 `long', `long long', `short', `void *', `float', `double', `long 2066 double', `size_t', `wchar_t', `wint_t' and `ptrdiff_t'. 2067 2068`__DEPRECATED' 2069 This macro is defined, with value 1, when compiling a C++ source 2070 file with warnings about deprecated constructs enabled. These 2071 warnings are enabled by default, but can be disabled with 2072 `-Wno-deprecated'. 2073 2074`__EXCEPTIONS' 2075 This macro is defined, with value 1, when compiling a C++ source 2076 file with exceptions enabled. If `-fno-exceptions' is used when 2077 compiling the file, then this macro is not defined. 2078 2079`__GXX_RTTI' 2080 This macro is defined, with value 1, when compiling a C++ source 2081 file with runtime type identification enabled. If `-fno-rtti' is 2082 used when compiling the file, then this macro is not defined. 2083 2084`__USING_SJLJ_EXCEPTIONS__' 2085 This macro is defined, with value 1, if the compiler uses the old 2086 mechanism based on `setjmp' and `longjmp' for exception handling. 2087 2088`__GXX_EXPERIMENTAL_CXX0X__' 2089 This macro is defined when compiling a C++ source file with the 2090 option `-std=c++0x' or `-std=gnu++0x'. It indicates that some 2091 features likely to be included in C++0x are available. Note that 2092 these features are experimental, and may change or be removed in 2093 future versions of GCC. 2094 2095`__GXX_WEAK__' 2096 This macro is defined when compiling a C++ source file. It has the 2097 value 1 if the compiler will use weak symbols, COMDAT sections, or 2098 other similar techniques to collapse symbols with "vague linkage" 2099 that are defined in multiple translation units. If the compiler 2100 will not collapse such symbols, this macro is defined with value 2101 0. In general, user code should not need to make use of this 2102 macro; the purpose of this macro is to ease implementation of the 2103 C++ runtime library provided with G++. 2104 2105`__NEXT_RUNTIME__' 2106 This macro is defined, with value 1, if (and only if) the NeXT 2107 runtime (as in `-fnext-runtime') is in use for Objective-C. If 2108 the GNU runtime is used, this macro is not defined, so that you 2109 can use this macro to determine which runtime (NeXT or GNU) is 2110 being used. 2111 2112`__LP64__' 2113`_LP64' 2114 These macros are defined, with value 1, if (and only if) the 2115 compilation is for a target where `long int' and pointer both use 2116 64-bits and `int' uses 32-bit. 2117 2118`__SSP__' 2119 This macro is defined, with value 1, when `-fstack-protector' is in 2120 use. 2121 2122`__SSP_ALL__' 2123 This macro is defined, with value 2, when `-fstack-protector-all' 2124 is in use. 2125 2126`__TIMESTAMP__' 2127 This macro expands to a string constant that describes the date 2128 and time of the last modification of the current source file. The 2129 string constant contains abbreviated day of the week, month, day 2130 of the month, time in hh:mm:ss form, year and looks like 2131 `"Sun Sep 16 01:03:52 1973"'. If the day of the month is less 2132 than 10, it is padded with a space on the left. 2133 2134 If GCC cannot determine the current date, it will emit a warning 2135 message (once per compilation) and `__TIMESTAMP__' will expand to 2136 `"??? ??? ?? ??:??:?? ????"'. 2137 2138`__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1' 2139`__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2' 2140`__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4' 2141`__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8' 2142`__GCC_HAVE_SYNC_COMPARE_AND_SWAP_16' 2143 These macros are defined when the target processor supports atomic 2144 compare and swap operations on operands 1, 2, 4, 8 or 16 bytes in 2145 length, respectively. 2146 2147`__GCC_HAVE_DWARF2_CFI_ASM' 2148 This macro is defined when the compiler is emitting Dwarf2 CFI 2149 directives to the assembler. When this is defined, it is possible 2150 to emit those same directives in inline assembly. 2151 2152 2153File: cpp.info, Node: System-specific Predefined Macros, Next: C++ Named Operators, Prev: Common Predefined Macros, Up: Predefined Macros 2154 21553.7.3 System-specific Predefined Macros 2156--------------------------------------- 2157 2158The C preprocessor normally predefines several macros that indicate what 2159type of system and machine is in use. They are obviously different on 2160each target supported by GCC. This manual, being for all systems and 2161machines, cannot tell you what their names are, but you can use `cpp 2162-dM' to see them all. *Note Invocation::. All system-specific 2163predefined macros expand to the constant 1, so you can test them with 2164either `#ifdef' or `#if'. 2165 2166 The C standard requires that all system-specific macros be part of 2167the "reserved namespace". All names which begin with two underscores, 2168or an underscore and a capital letter, are reserved for the compiler and 2169library to use as they wish. However, historically system-specific 2170macros have had names with no special prefix; for instance, it is common 2171to find `unix' defined on Unix systems. For all such macros, GCC 2172provides a parallel macro with two underscores added at the beginning 2173and the end. If `unix' is defined, `__unix__' will be defined too. 2174There will never be more than two underscores; the parallel of `_mips' 2175is `__mips__'. 2176 2177 When the `-ansi' option, or any `-std' option that requests strict 2178conformance, is given to the compiler, all the system-specific 2179predefined macros outside the reserved namespace are suppressed. The 2180parallel macros, inside the reserved namespace, remain defined. 2181 2182 We are slowly phasing out all predefined macros which are outside the 2183reserved namespace. You should never use them in new programs, and we 2184encourage you to correct older code to use the parallel macros whenever 2185you find it. We don't recommend you use the system-specific macros that 2186are in the reserved namespace, either. It is better in the long run to 2187check specifically for features you need, using a tool such as 2188`autoconf'. 2189 2190 2191File: cpp.info, Node: C++ Named Operators, Prev: System-specific Predefined Macros, Up: Predefined Macros 2192 21933.7.4 C++ Named Operators 2194------------------------- 2195 2196In C++, there are eleven keywords which are simply alternate spellings 2197of operators normally written with punctuation. These keywords are 2198treated as such even in the preprocessor. They function as operators in 2199`#if', and they cannot be defined as macros or poisoned. In C, you can 2200request that those keywords take their C++ meaning by including 2201`iso646.h'. That header defines each one as a normal object-like macro 2202expanding to the appropriate punctuator. 2203 2204 These are the named operators and their corresponding punctuators: 2205 2206Named Operator Punctuator 2207`and' `&&' 2208`and_eq' `&=' 2209`bitand' `&' 2210`bitor' `|' 2211`compl' `~' 2212`not' `!' 2213`not_eq' `!=' 2214`or' `||' 2215`or_eq' `|=' 2216`xor' `^' 2217`xor_eq' `^=' 2218 2219 2220File: cpp.info, Node: Undefining and Redefining Macros, Next: Directives Within Macro Arguments, Prev: Predefined Macros, Up: Macros 2221 22223.8 Undefining and Redefining Macros 2223==================================== 2224 2225If a macro ceases to be useful, it may be "undefined" with the `#undef' 2226directive. `#undef' takes a single argument, the name of the macro to 2227undefine. You use the bare macro name, even if the macro is 2228function-like. It is an error if anything appears on the line after 2229the macro name. `#undef' has no effect if the name is not a macro. 2230 2231 #define FOO 4 2232 x = FOO; ==> x = 4; 2233 #undef FOO 2234 x = FOO; ==> x = FOO; 2235 2236 Once a macro has been undefined, that identifier may be "redefined" 2237as a macro by a subsequent `#define' directive. The new definition 2238need not have any resemblance to the old definition. 2239 2240 However, if an identifier which is currently a macro is redefined, 2241then the new definition must be "effectively the same" as the old one. 2242Two macro definitions are effectively the same if: 2243 * Both are the same type of macro (object- or function-like). 2244 2245 * All the tokens of the replacement list are the same. 2246 2247 * If there are any parameters, they are the same. 2248 2249 * Whitespace appears in the same places in both. It need not be 2250 exactly the same amount of whitespace, though. Remember that 2251 comments count as whitespace. 2252 2253These definitions are effectively the same: 2254 #define FOUR (2 + 2) 2255 #define FOUR (2 + 2) 2256 #define FOUR (2 /* two */ + 2) 2257 but these are not: 2258 #define FOUR (2 + 2) 2259 #define FOUR ( 2+2 ) 2260 #define FOUR (2 * 2) 2261 #define FOUR(score,and,seven,years,ago) (2 + 2) 2262 2263 If a macro is redefined with a definition that is not effectively the 2264same as the old one, the preprocessor issues a warning and changes the 2265macro to use the new definition. If the new definition is effectively 2266the same, the redefinition is silently ignored. This allows, for 2267instance, two different headers to define a common macro. The 2268preprocessor will only complain if the definitions do not match. 2269 2270 2271File: cpp.info, Node: Directives Within Macro Arguments, Next: Macro Pitfalls, Prev: Undefining and Redefining Macros, Up: Macros 2272 22733.9 Directives Within Macro Arguments 2274===================================== 2275 2276Occasionally it is convenient to use preprocessor directives within the 2277arguments of a macro. The C and C++ standards declare that behavior in 2278these cases is undefined. 2279 2280 Versions of CPP prior to 3.2 would reject such constructs with an 2281error message. This was the only syntactic difference between normal 2282functions and function-like macros, so it seemed attractive to remove 2283this limitation, and people would often be surprised that they could 2284not use macros in this way. Moreover, sometimes people would use 2285conditional compilation in the argument list to a normal library 2286function like `printf', only to find that after a library upgrade 2287`printf' had changed to be a function-like macro, and their code would 2288no longer compile. So from version 3.2 we changed CPP to successfully 2289process arbitrary directives within macro arguments in exactly the same 2290way as it would have processed the directive were the function-like 2291macro invocation not present. 2292 2293 If, within a macro invocation, that macro is redefined, then the new 2294definition takes effect in time for argument pre-expansion, but the 2295original definition is still used for argument replacement. Here is a 2296pathological example: 2297 2298 #define f(x) x x 2299 f (1 2300 #undef f 2301 #define f 2 2302 f) 2303 2304which expands to 2305 2306 1 2 1 2 2307 2308with the semantics described above. 2309 2310 2311File: cpp.info, Node: Macro Pitfalls, Prev: Directives Within Macro Arguments, Up: Macros 2312 23133.10 Macro Pitfalls 2314=================== 2315 2316In this section we describe some special rules that apply to macros and 2317macro expansion, and point out certain cases in which the rules have 2318counter-intuitive consequences that you must watch out for. 2319 2320* Menu: 2321 2322* Misnesting:: 2323* Operator Precedence Problems:: 2324* Swallowing the Semicolon:: 2325* Duplication of Side Effects:: 2326* Self-Referential Macros:: 2327* Argument Prescan:: 2328* Newlines in Arguments:: 2329 2330 2331File: cpp.info, Node: Misnesting, Next: Operator Precedence Problems, Up: Macro Pitfalls 2332 23333.10.1 Misnesting 2334----------------- 2335 2336When a macro is called with arguments, the arguments are substituted 2337into the macro body and the result is checked, together with the rest of 2338the input file, for more macro calls. It is possible to piece together 2339a macro call coming partially from the macro body and partially from the 2340arguments. For example, 2341 2342 #define twice(x) (2*(x)) 2343 #define call_with_1(x) x(1) 2344 call_with_1 (twice) 2345 ==> twice(1) 2346 ==> (2*(1)) 2347 2348 Macro definitions do not have to have balanced parentheses. By 2349writing an unbalanced open parenthesis in a macro body, it is possible 2350to create a macro call that begins inside the macro body but ends 2351outside of it. For example, 2352 2353 #define strange(file) fprintf (file, "%s %d", 2354 ... 2355 strange(stderr) p, 35) 2356 ==> fprintf (stderr, "%s %d", p, 35) 2357 2358 The ability to piece together a macro call can be useful, but the 2359use of unbalanced open parentheses in a macro body is just confusing, 2360and should be avoided. 2361 2362 2363File: cpp.info, Node: Operator Precedence Problems, Next: Swallowing the Semicolon, Prev: Misnesting, Up: Macro Pitfalls 2364 23653.10.2 Operator Precedence Problems 2366----------------------------------- 2367 2368You may have noticed that in most of the macro definition examples shown 2369above, each occurrence of a macro argument name had parentheses around 2370it. In addition, another pair of parentheses usually surround the 2371entire macro definition. Here is why it is best to write macros that 2372way. 2373 2374 Suppose you define a macro as follows, 2375 2376 #define ceil_div(x, y) (x + y - 1) / y 2377 2378whose purpose is to divide, rounding up. (One use for this operation is 2379to compute how many `int' objects are needed to hold a certain number 2380of `char' objects.) Then suppose it is used as follows: 2381 2382 a = ceil_div (b & c, sizeof (int)); 2383 ==> a = (b & c + sizeof (int) - 1) / sizeof (int); 2384 2385This does not do what is intended. The operator-precedence rules of C 2386make it equivalent to this: 2387 2388 a = (b & (c + sizeof (int) - 1)) / sizeof (int); 2389 2390What we want is this: 2391 2392 a = ((b & c) + sizeof (int) - 1)) / sizeof (int); 2393 2394Defining the macro as 2395 2396 #define ceil_div(x, y) ((x) + (y) - 1) / (y) 2397 2398provides the desired result. 2399 2400 Unintended grouping can result in another way. Consider `sizeof 2401ceil_div(1, 2)'. That has the appearance of a C expression that would 2402compute the size of the type of `ceil_div (1, 2)', but in fact it means 2403something very different. Here is what it expands to: 2404 2405 sizeof ((1) + (2) - 1) / (2) 2406 2407This would take the size of an integer and divide it by two. The 2408precedence rules have put the division outside the `sizeof' when it was 2409intended to be inside. 2410 2411 Parentheses around the entire macro definition prevent such problems. 2412Here, then, is the recommended way to define `ceil_div': 2413 2414 #define ceil_div(x, y) (((x) + (y) - 1) / (y)) 2415 2416 2417File: cpp.info, Node: Swallowing the Semicolon, Next: Duplication of Side Effects, Prev: Operator Precedence Problems, Up: Macro Pitfalls 2418 24193.10.3 Swallowing the Semicolon 2420------------------------------- 2421 2422Often it is desirable to define a macro that expands into a compound 2423statement. Consider, for example, the following macro, that advances a 2424pointer (the argument `p' says where to find it) across whitespace 2425characters: 2426 2427 #define SKIP_SPACES(p, limit) \ 2428 { char *lim = (limit); \ 2429 while (p < lim) { \ 2430 if (*p++ != ' ') { \ 2431 p--; break; }}} 2432 2433Here backslash-newline is used to split the macro definition, which must 2434be a single logical line, so that it resembles the way such code would 2435be laid out if not part of a macro definition. 2436 2437 A call to this macro might be `SKIP_SPACES (p, lim)'. Strictly 2438speaking, the call expands to a compound statement, which is a complete 2439statement with no need for a semicolon to end it. However, since it 2440looks like a function call, it minimizes confusion if you can use it 2441like a function call, writing a semicolon afterward, as in `SKIP_SPACES 2442(p, lim);' 2443 2444 This can cause trouble before `else' statements, because the 2445semicolon is actually a null statement. Suppose you write 2446 2447 if (*p != 0) 2448 SKIP_SPACES (p, lim); 2449 else ... 2450 2451The presence of two statements--the compound statement and a null 2452statement--in between the `if' condition and the `else' makes invalid C 2453code. 2454 2455 The definition of the macro `SKIP_SPACES' can be altered to solve 2456this problem, using a `do ... while' statement. Here is how: 2457 2458 #define SKIP_SPACES(p, limit) \ 2459 do { char *lim = (limit); \ 2460 while (p < lim) { \ 2461 if (*p++ != ' ') { \ 2462 p--; break; }}} \ 2463 while (0) 2464 2465 Now `SKIP_SPACES (p, lim);' expands into 2466 2467 do {...} while (0); 2468 2469which is one statement. The loop executes exactly once; most compilers 2470generate no extra code for it. 2471 2472 2473File: cpp.info, Node: Duplication of Side Effects, Next: Self-Referential Macros, Prev: Swallowing the Semicolon, Up: Macro Pitfalls 2474 24753.10.4 Duplication of Side Effects 2476---------------------------------- 2477 2478Many C programs define a macro `min', for "minimum", like this: 2479 2480 #define min(X, Y) ((X) < (Y) ? (X) : (Y)) 2481 2482 When you use this macro with an argument containing a side effect, 2483as shown here, 2484 2485 next = min (x + y, foo (z)); 2486 2487it expands as follows: 2488 2489 next = ((x + y) < (foo (z)) ? (x + y) : (foo (z))); 2490 2491where `x + y' has been substituted for `X' and `foo (z)' for `Y'. 2492 2493 The function `foo' is used only once in the statement as it appears 2494in the program, but the expression `foo (z)' has been substituted twice 2495into the macro expansion. As a result, `foo' might be called two times 2496when the statement is executed. If it has side effects or if it takes 2497a long time to compute, the results might not be what you intended. We 2498say that `min' is an "unsafe" macro. 2499 2500 The best solution to this problem is to define `min' in a way that 2501computes the value of `foo (z)' only once. The C language offers no 2502standard way to do this, but it can be done with GNU extensions as 2503follows: 2504 2505 #define min(X, Y) \ 2506 ({ typeof (X) x_ = (X); \ 2507 typeof (Y) y_ = (Y); \ 2508 (x_ < y_) ? x_ : y_; }) 2509 2510 The `({ ... })' notation produces a compound statement that acts as 2511an expression. Its value is the value of its last statement. This 2512permits us to define local variables and assign each argument to one. 2513The local variables have underscores after their names to reduce the 2514risk of conflict with an identifier of wider scope (it is impossible to 2515avoid this entirely). Now each argument is evaluated exactly once. 2516 2517 If you do not wish to use GNU C extensions, the only solution is to 2518be careful when _using_ the macro `min'. For example, you can 2519calculate the value of `foo (z)', save it in a variable, and use that 2520variable in `min': 2521 2522 #define min(X, Y) ((X) < (Y) ? (X) : (Y)) 2523 ... 2524 { 2525 int tem = foo (z); 2526 next = min (x + y, tem); 2527 } 2528 2529(where we assume that `foo' returns type `int'). 2530 2531 2532File: cpp.info, Node: Self-Referential Macros, Next: Argument Prescan, Prev: Duplication of Side Effects, Up: Macro Pitfalls 2533 25343.10.5 Self-Referential Macros 2535------------------------------ 2536 2537A "self-referential" macro is one whose name appears in its definition. 2538Recall that all macro definitions are rescanned for more macros to 2539replace. If the self-reference were considered a use of the macro, it 2540would produce an infinitely large expansion. To prevent this, the 2541self-reference is not considered a macro call. It is passed into the 2542preprocessor output unchanged. Consider an example: 2543 2544 #define foo (4 + foo) 2545 2546where `foo' is also a variable in your program. 2547 2548 Following the ordinary rules, each reference to `foo' will expand 2549into `(4 + foo)'; then this will be rescanned and will expand into `(4 2550+ (4 + foo))'; and so on until the computer runs out of memory. 2551 2552 The self-reference rule cuts this process short after one step, at 2553`(4 + foo)'. Therefore, this macro definition has the possibly useful 2554effect of causing the program to add 4 to the value of `foo' wherever 2555`foo' is referred to. 2556 2557 In most cases, it is a bad idea to take advantage of this feature. A 2558person reading the program who sees that `foo' is a variable will not 2559expect that it is a macro as well. The reader will come across the 2560identifier `foo' in the program and think its value should be that of 2561the variable `foo', whereas in fact the value is four greater. 2562 2563 One common, useful use of self-reference is to create a macro which 2564expands to itself. If you write 2565 2566 #define EPERM EPERM 2567 2568then the macro `EPERM' expands to `EPERM'. Effectively, it is left 2569alone by the preprocessor whenever it's used in running text. You can 2570tell that it's a macro with `#ifdef'. You might do this if you want to 2571define numeric constants with an `enum', but have `#ifdef' be true for 2572each constant. 2573 2574 If a macro `x' expands to use a macro `y', and the expansion of `y' 2575refers to the macro `x', that is an "indirect self-reference" of `x'. 2576`x' is not expanded in this case either. Thus, if we have 2577 2578 #define x (4 + y) 2579 #define y (2 * x) 2580 2581then `x' and `y' expand as follows: 2582 2583 x ==> (4 + y) 2584 ==> (4 + (2 * x)) 2585 2586 y ==> (2 * x) 2587 ==> (2 * (4 + y)) 2588 2589Each macro is expanded when it appears in the definition of the other 2590macro, but not when it indirectly appears in its own definition. 2591 2592 2593File: cpp.info, Node: Argument Prescan, Next: Newlines in Arguments, Prev: Self-Referential Macros, Up: Macro Pitfalls 2594 25953.10.6 Argument Prescan 2596----------------------- 2597 2598Macro arguments are completely macro-expanded before they are 2599substituted into a macro body, unless they are stringified or pasted 2600with other tokens. After substitution, the entire macro body, including 2601the substituted arguments, is scanned again for macros to be expanded. 2602The result is that the arguments are scanned _twice_ to expand macro 2603calls in them. 2604 2605 Most of the time, this has no effect. If the argument contained any 2606macro calls, they are expanded during the first scan. The result 2607therefore contains no macro calls, so the second scan does not change 2608it. If the argument were substituted as given, with no prescan, the 2609single remaining scan would find the same macro calls and produce the 2610same results. 2611 2612 You might expect the double scan to change the results when a 2613self-referential macro is used in an argument of another macro (*note 2614Self-Referential Macros::): the self-referential macro would be 2615expanded once in the first scan, and a second time in the second scan. 2616However, this is not what happens. The self-references that do not 2617expand in the first scan are marked so that they will not expand in the 2618second scan either. 2619 2620 You might wonder, "Why mention the prescan, if it makes no 2621difference? And why not skip it and make the preprocessor faster?" 2622The answer is that the prescan does make a difference in three special 2623cases: 2624 2625 * Nested calls to a macro. 2626 2627 We say that "nested" calls to a macro occur when a macro's argument 2628 contains a call to that very macro. For example, if `f' is a macro 2629 that expects one argument, `f (f (1))' is a nested pair of calls to 2630 `f'. The desired expansion is made by expanding `f (1)' and 2631 substituting that into the definition of `f'. The prescan causes 2632 the expected result to happen. Without the prescan, `f (1)' itself 2633 would be substituted as an argument, and the inner use of `f' would 2634 appear during the main scan as an indirect self-reference and 2635 would not be expanded. 2636 2637 * Macros that call other macros that stringify or concatenate. 2638 2639 If an argument is stringified or concatenated, the prescan does not 2640 occur. If you _want_ to expand a macro, then stringify or 2641 concatenate its expansion, you can do that by causing one macro to 2642 call another macro that does the stringification or concatenation. 2643 For instance, if you have 2644 2645 #define AFTERX(x) X_ ## x 2646 #define XAFTERX(x) AFTERX(x) 2647 #define TABLESIZE 1024 2648 #define BUFSIZE TABLESIZE 2649 2650 then `AFTERX(BUFSIZE)' expands to `X_BUFSIZE', and 2651 `XAFTERX(BUFSIZE)' expands to `X_1024'. (Not to `X_TABLESIZE'. 2652 Prescan always does a complete expansion.) 2653 2654 * Macros used in arguments, whose expansions contain unshielded 2655 commas. 2656 2657 This can cause a macro expanded on the second scan to be called 2658 with the wrong number of arguments. Here is an example: 2659 2660 #define foo a,b 2661 #define bar(x) lose(x) 2662 #define lose(x) (1 + (x)) 2663 2664 We would like `bar(foo)' to turn into `(1 + (foo))', which would 2665 then turn into `(1 + (a,b))'. Instead, `bar(foo)' expands into 2666 `lose(a,b)', and you get an error because `lose' requires a single 2667 argument. In this case, the problem is easily solved by the same 2668 parentheses that ought to be used to prevent misnesting of 2669 arithmetic operations: 2670 2671 #define foo (a,b) 2672 or 2673 #define bar(x) lose((x)) 2674 2675 The extra pair of parentheses prevents the comma in `foo''s 2676 definition from being interpreted as an argument separator. 2677 2678 2679 2680File: cpp.info, Node: Newlines in Arguments, Prev: Argument Prescan, Up: Macro Pitfalls 2681 26823.10.7 Newlines in Arguments 2683---------------------------- 2684 2685The invocation of a function-like macro can extend over many logical 2686lines. However, in the present implementation, the entire expansion 2687comes out on one line. Thus line numbers emitted by the compiler or 2688debugger refer to the line the invocation started on, which might be 2689different to the line containing the argument causing the problem. 2690 2691 Here is an example illustrating this: 2692 2693 #define ignore_second_arg(a,b,c) a; c 2694 2695 ignore_second_arg (foo (), 2696 ignored (), 2697 syntax error); 2698 2699The syntax error triggered by the tokens `syntax error' results in an 2700error message citing line three--the line of ignore_second_arg-- even 2701though the problematic code comes from line five. 2702 2703 We consider this a bug, and intend to fix it in the near future. 2704 2705 2706File: cpp.info, Node: Conditionals, Next: Diagnostics, Prev: Macros, Up: Top 2707 27084 Conditionals 2709************** 2710 2711A "conditional" is a directive that instructs the preprocessor to 2712select whether or not to include a chunk of code in the final token 2713stream passed to the compiler. Preprocessor conditionals can test 2714arithmetic expressions, or whether a name is defined as a macro, or both 2715simultaneously using the special `defined' operator. 2716 2717 A conditional in the C preprocessor resembles in some ways an `if' 2718statement in C, but it is important to understand the difference between 2719them. The condition in an `if' statement is tested during the 2720execution of your program. Its purpose is to allow your program to 2721behave differently from run to run, depending on the data it is 2722operating on. The condition in a preprocessing conditional directive is 2723tested when your program is compiled. Its purpose is to allow different 2724code to be included in the program depending on the situation at the 2725time of compilation. 2726 2727 However, the distinction is becoming less clear. Modern compilers 2728often do test `if' statements when a program is compiled, if their 2729conditions are known not to vary at run time, and eliminate code which 2730can never be executed. If you can count on your compiler to do this, 2731you may find that your program is more readable if you use `if' 2732statements with constant conditions (perhaps determined by macros). Of 2733course, you can only use this to exclude code, not type definitions or 2734other preprocessing directives, and you can only do it if the code 2735remains syntactically valid when it is not to be used. 2736 2737 GCC version 3 eliminates this kind of never-executed code even when 2738not optimizing. Older versions did it only when optimizing. 2739 2740* Menu: 2741 2742* Conditional Uses:: 2743* Conditional Syntax:: 2744* Deleted Code:: 2745 2746 2747File: cpp.info, Node: Conditional Uses, Next: Conditional Syntax, Up: Conditionals 2748 27494.1 Conditional Uses 2750==================== 2751 2752There are three general reasons to use a conditional. 2753 2754 * A program may need to use different code depending on the machine 2755 or operating system it is to run on. In some cases the code for 2756 one operating system may be erroneous on another operating system; 2757 for example, it might refer to data types or constants that do not 2758 exist on the other system. When this happens, it is not enough to 2759 avoid executing the invalid code. Its mere presence will cause 2760 the compiler to reject the program. With a preprocessing 2761 conditional, the offending code can be effectively excised from 2762 the program when it is not valid. 2763 2764 * You may want to be able to compile the same source file into two 2765 different programs. One version might make frequent time-consuming 2766 consistency checks on its intermediate data, or print the values of 2767 those data for debugging, and the other not. 2768 2769 * A conditional whose condition is always false is one way to 2770 exclude code from the program but keep it as a sort of comment for 2771 future reference. 2772 2773 Simple programs that do not need system-specific logic or complex 2774debugging hooks generally will not need to use preprocessing 2775conditionals. 2776 2777 2778File: cpp.info, Node: Conditional Syntax, Next: Deleted Code, Prev: Conditional Uses, Up: Conditionals 2779 27804.2 Conditional Syntax 2781====================== 2782 2783A conditional in the C preprocessor begins with a "conditional 2784directive": `#if', `#ifdef' or `#ifndef'. 2785 2786* Menu: 2787 2788* Ifdef:: 2789* If:: 2790* Defined:: 2791* Else:: 2792* Elif:: 2793 2794 2795File: cpp.info, Node: Ifdef, Next: If, Up: Conditional Syntax 2796 27974.2.1 Ifdef 2798----------- 2799 2800The simplest sort of conditional is 2801 2802 #ifdef MACRO 2803 2804 CONTROLLED TEXT 2805 2806 #endif /* MACRO */ 2807 2808 This block is called a "conditional group". CONTROLLED TEXT will be 2809included in the output of the preprocessor if and only if MACRO is 2810defined. We say that the conditional "succeeds" if MACRO is defined, 2811"fails" if it is not. 2812 2813 The CONTROLLED TEXT inside of a conditional can include 2814preprocessing directives. They are executed only if the conditional 2815succeeds. You can nest conditional groups inside other conditional 2816groups, but they must be completely nested. In other words, `#endif' 2817always matches the nearest `#ifdef' (or `#ifndef', or `#if'). Also, 2818you cannot start a conditional group in one file and end it in another. 2819 2820 Even if a conditional fails, the CONTROLLED TEXT inside it is still 2821run through initial transformations and tokenization. Therefore, it 2822must all be lexically valid C. Normally the only way this matters is 2823that all comments and string literals inside a failing conditional group 2824must still be properly ended. 2825 2826 The comment following the `#endif' is not required, but it is a good 2827practice if there is a lot of CONTROLLED TEXT, because it helps people 2828match the `#endif' to the corresponding `#ifdef'. Older programs 2829sometimes put MACRO directly after the `#endif' without enclosing it in 2830a comment. This is invalid code according to the C standard. CPP 2831accepts it with a warning. It never affects which `#ifndef' the 2832`#endif' matches. 2833 2834 Sometimes you wish to use some code if a macro is _not_ defined. 2835You can do this by writing `#ifndef' instead of `#ifdef'. One common 2836use of `#ifndef' is to include code only the first time a header file 2837is included. *Note Once-Only Headers::. 2838 2839 Macro definitions can vary between compilations for several reasons. 2840Here are some samples. 2841 2842 * Some macros are predefined on each kind of machine (*note 2843 System-specific Predefined Macros::). This allows you to provide 2844 code specially tuned for a particular machine. 2845 2846 * System header files define more macros, associated with the 2847 features they implement. You can test these macros with 2848 conditionals to avoid using a system feature on a machine where it 2849 is not implemented. 2850 2851 * Macros can be defined or undefined with the `-D' and `-U' command 2852 line options when you compile the program. You can arrange to 2853 compile the same source file into two different programs by 2854 choosing a macro name to specify which program you want, writing 2855 conditionals to test whether or how this macro is defined, and 2856 then controlling the state of the macro with command line options, 2857 perhaps set in the Makefile. *Note Invocation::. 2858 2859 * Your program might have a special header file (often called 2860 `config.h') that is adjusted when the program is compiled. It can 2861 define or not define macros depending on the features of the 2862 system and the desired capabilities of the program. The 2863 adjustment can be automated by a tool such as `autoconf', or done 2864 by hand. 2865 2866 2867File: cpp.info, Node: If, Next: Defined, Prev: Ifdef, Up: Conditional Syntax 2868 28694.2.2 If 2870-------- 2871 2872The `#if' directive allows you to test the value of an arithmetic 2873expression, rather than the mere existence of one macro. Its syntax is 2874 2875 #if EXPRESSION 2876 2877 CONTROLLED TEXT 2878 2879 #endif /* EXPRESSION */ 2880 2881 EXPRESSION is a C expression of integer type, subject to stringent 2882restrictions. It may contain 2883 2884 * Integer constants. 2885 2886 * Character constants, which are interpreted as they would be in 2887 normal code. 2888 2889 * Arithmetic operators for addition, subtraction, multiplication, 2890 division, bitwise operations, shifts, comparisons, and logical 2891 operations (`&&' and `||'). The latter two obey the usual 2892 short-circuiting rules of standard C. 2893 2894 * Macros. All macros in the expression are expanded before actual 2895 computation of the expression's value begins. 2896 2897 * Uses of the `defined' operator, which lets you check whether macros 2898 are defined in the middle of an `#if'. 2899 2900 * Identifiers that are not macros, which are all considered to be the 2901 number zero. This allows you to write `#if MACRO' instead of 2902 `#ifdef MACRO', if you know that MACRO, when defined, will always 2903 have a nonzero value. Function-like macros used without their 2904 function call parentheses are also treated as zero. 2905 2906 In some contexts this shortcut is undesirable. The `-Wundef' 2907 option causes GCC to warn whenever it encounters an identifier 2908 which is not a macro in an `#if'. 2909 2910 The preprocessor does not know anything about types in the language. 2911Therefore, `sizeof' operators are not recognized in `#if', and neither 2912are `enum' constants. They will be taken as identifiers which are not 2913macros, and replaced by zero. In the case of `sizeof', this is likely 2914to cause the expression to be invalid. 2915 2916 The preprocessor calculates the value of EXPRESSION. It carries out 2917all calculations in the widest integer type known to the compiler; on 2918most machines supported by GCC this is 64 bits. This is not the same 2919rule as the compiler uses to calculate the value of a constant 2920expression, and may give different results in some cases. If the value 2921comes out to be nonzero, the `#if' succeeds and the CONTROLLED TEXT is 2922included; otherwise it is skipped. 2923 2924 2925File: cpp.info, Node: Defined, Next: Else, Prev: If, Up: Conditional Syntax 2926 29274.2.3 Defined 2928------------- 2929 2930The special operator `defined' is used in `#if' and `#elif' expressions 2931to test whether a certain name is defined as a macro. `defined NAME' 2932and `defined (NAME)' are both expressions whose value is 1 if NAME is 2933defined as a macro at the current point in the program, and 0 2934otherwise. Thus, `#if defined MACRO' is precisely equivalent to 2935`#ifdef MACRO'. 2936 2937 `defined' is useful when you wish to test more than one macro for 2938existence at once. For example, 2939 2940 #if defined (__vax__) || defined (__ns16000__) 2941 2942would succeed if either of the names `__vax__' or `__ns16000__' is 2943defined as a macro. 2944 2945 Conditionals written like this: 2946 2947 #if defined BUFSIZE && BUFSIZE >= 1024 2948 2949can generally be simplified to just `#if BUFSIZE >= 1024', since if 2950`BUFSIZE' is not defined, it will be interpreted as having the value 2951zero. 2952 2953 If the `defined' operator appears as a result of a macro expansion, 2954the C standard says the behavior is undefined. GNU cpp treats it as a 2955genuine `defined' operator and evaluates it normally. It will warn 2956wherever your code uses this feature if you use the command-line option 2957`-pedantic', since other compilers may handle it differently. 2958 2959 2960File: cpp.info, Node: Else, Next: Elif, Prev: Defined, Up: Conditional Syntax 2961 29624.2.4 Else 2963---------- 2964 2965The `#else' directive can be added to a conditional to provide 2966alternative text to be used if the condition fails. This is what it 2967looks like: 2968 2969 #if EXPRESSION 2970 TEXT-IF-TRUE 2971 #else /* Not EXPRESSION */ 2972 TEXT-IF-FALSE 2973 #endif /* Not EXPRESSION */ 2974 2975If EXPRESSION is nonzero, the TEXT-IF-TRUE is included and the 2976TEXT-IF-FALSE is skipped. If EXPRESSION is zero, the opposite happens. 2977 2978 You can use `#else' with `#ifdef' and `#ifndef', too. 2979 2980 2981File: cpp.info, Node: Elif, Prev: Else, Up: Conditional Syntax 2982 29834.2.5 Elif 2984---------- 2985 2986One common case of nested conditionals is used to check for more than 2987two possible alternatives. For example, you might have 2988 2989 #if X == 1 2990 ... 2991 #else /* X != 1 */ 2992 #if X == 2 2993 ... 2994 #else /* X != 2 */ 2995 ... 2996 #endif /* X != 2 */ 2997 #endif /* X != 1 */ 2998 2999 Another conditional directive, `#elif', allows this to be 3000abbreviated as follows: 3001 3002 #if X == 1 3003 ... 3004 #elif X == 2 3005 ... 3006 #else /* X != 2 and X != 1*/ 3007 ... 3008 #endif /* X != 2 and X != 1*/ 3009 3010 `#elif' stands for "else if". Like `#else', it goes in the middle 3011of a conditional group and subdivides it; it does not require a 3012matching `#endif' of its own. Like `#if', the `#elif' directive 3013includes an expression to be tested. The text following the `#elif' is 3014processed only if the original `#if'-condition failed and the `#elif' 3015condition succeeds. 3016 3017 More than one `#elif' can go in the same conditional group. Then 3018the text after each `#elif' is processed only if the `#elif' condition 3019succeeds after the original `#if' and all previous `#elif' directives 3020within it have failed. 3021 3022 `#else' is allowed after any number of `#elif' directives, but 3023`#elif' may not follow `#else'. 3024 3025 3026File: cpp.info, Node: Deleted Code, Prev: Conditional Syntax, Up: Conditionals 3027 30284.3 Deleted Code 3029================ 3030 3031If you replace or delete a part of the program but want to keep the old 3032code around for future reference, you often cannot simply comment it 3033out. Block comments do not nest, so the first comment inside the old 3034code will end the commenting-out. The probable result is a flood of 3035syntax errors. 3036 3037 One way to avoid this problem is to use an always-false conditional 3038instead. For instance, put `#if 0' before the deleted code and 3039`#endif' after it. This works even if the code being turned off 3040contains conditionals, but they must be entire conditionals (balanced 3041`#if' and `#endif'). 3042 3043 Some people use `#ifdef notdef' instead. This is risky, because 3044`notdef' might be accidentally defined as a macro, and then the 3045conditional would succeed. `#if 0' can be counted on to fail. 3046 3047 Do not use `#if 0' for comments which are not C code. Use a real 3048comment, instead. The interior of `#if 0' must consist of complete 3049tokens; in particular, single-quote characters must balance. Comments 3050often contain unbalanced single-quote characters (known in English as 3051apostrophes). These confuse `#if 0'. They don't confuse `/*'. 3052 3053 3054File: cpp.info, Node: Diagnostics, Next: Line Control, Prev: Conditionals, Up: Top 3055 30565 Diagnostics 3057************* 3058 3059The directive `#error' causes the preprocessor to report a fatal error. 3060The tokens forming the rest of the line following `#error' are used as 3061the error message. 3062 3063 You would use `#error' inside of a conditional that detects a 3064combination of parameters which you know the program does not properly 3065support. For example, if you know that the program will not run 3066properly on a VAX, you might write 3067 3068 #ifdef __vax__ 3069 #error "Won't work on VAXen. See comments at get_last_object." 3070 #endif 3071 3072 If you have several configuration parameters that must be set up by 3073the installation in a consistent way, you can use conditionals to detect 3074an inconsistency and report it with `#error'. For example, 3075 3076 #if !defined(UNALIGNED_INT_ASM_OP) && defined(DWARF2_DEBUGGING_INFO) 3077 #error "DWARF2_DEBUGGING_INFO requires UNALIGNED_INT_ASM_OP." 3078 #endif 3079 3080 The directive `#warning' is like `#error', but causes the 3081preprocessor to issue a warning and continue preprocessing. The tokens 3082following `#warning' are used as the warning message. 3083 3084 You might use `#warning' in obsolete header files, with a message 3085directing the user to the header file which should be used instead. 3086 3087 Neither `#error' nor `#warning' macro-expands its argument. 3088Internal whitespace sequences are each replaced with a single space. 3089The line must consist of complete tokens. It is wisest to make the 3090argument of these directives be a single string constant; this avoids 3091problems with apostrophes and the like. 3092 3093 3094File: cpp.info, Node: Line Control, Next: Pragmas, Prev: Diagnostics, Up: Top 3095 30966 Line Control 3097************** 3098 3099The C preprocessor informs the C compiler of the location in your source 3100code where each token came from. Presently, this is just the file name 3101and line number. All the tokens resulting from macro expansion are 3102reported as having appeared on the line of the source file where the 3103outermost macro was used. We intend to be more accurate in the future. 3104 3105 If you write a program which generates source code, such as the 3106`bison' parser generator, you may want to adjust the preprocessor's 3107notion of the current file name and line number by hand. Parts of the 3108output from `bison' are generated from scratch, other parts come from a 3109standard parser file. The rest are copied verbatim from `bison''s 3110input. You would like compiler error messages and symbolic debuggers 3111to be able to refer to `bison''s input file. 3112 3113 `bison' or any such program can arrange this by writing `#line' 3114directives into the output file. `#line' is a directive that specifies 3115the original line number and source file name for subsequent input in 3116the current preprocessor input file. `#line' has three variants: 3117 3118`#line LINENUM' 3119 LINENUM is a non-negative decimal integer constant. It specifies 3120 the line number which should be reported for the following line of 3121 input. Subsequent lines are counted from LINENUM. 3122 3123`#line LINENUM FILENAME' 3124 LINENUM is the same as for the first form, and has the same 3125 effect. In addition, FILENAME is a string constant. The 3126 following line and all subsequent lines are reported to come from 3127 the file it specifies, until something else happens to change that. 3128 FILENAME is interpreted according to the normal rules for a string 3129 constant: backslash escapes are interpreted. This is different 3130 from `#include'. 3131 3132 Previous versions of CPP did not interpret escapes in `#line'; we 3133 have changed it because the standard requires they be interpreted, 3134 and most other compilers do. 3135 3136`#line ANYTHING ELSE' 3137 ANYTHING ELSE is checked for macro calls, which are expanded. The 3138 result should match one of the above two forms. 3139 3140 `#line' directives alter the results of the `__FILE__' and 3141`__LINE__' predefined macros from that point on. *Note Standard 3142Predefined Macros::. They do not have any effect on `#include''s idea 3143of the directory containing the current file. This is a change from 3144GCC 2.95. Previously, a file reading 3145 3146 #line 1 "../src/gram.y" 3147 #include "gram.h" 3148 3149 would search for `gram.h' in `../src', then the `-I' chain; the 3150directory containing the physical source file would not be searched. 3151In GCC 3.0 and later, the `#include' is not affected by the presence of 3152a `#line' referring to a different directory. 3153 3154 We made this change because the old behavior caused problems when 3155generated source files were transported between machines. For instance, 3156it is common practice to ship generated parsers with a source release, 3157so that people building the distribution do not need to have yacc or 3158Bison installed. These files frequently have `#line' directives 3159referring to the directory tree of the system where the distribution was 3160created. If GCC tries to search for headers in those directories, the 3161build is likely to fail. 3162 3163 The new behavior can cause failures too, if the generated file is not 3164in the same directory as its source and it attempts to include a header 3165which would be visible searching from the directory containing the 3166source file. However, this problem is easily solved with an additional 3167`-I' switch on the command line. The failures caused by the old 3168semantics could sometimes be corrected only by editing the generated 3169files, which is difficult and error-prone. 3170 3171 3172File: cpp.info, Node: Pragmas, Next: Other Directives, Prev: Line Control, Up: Top 3173 31747 Pragmas 3175********* 3176 3177The `#pragma' directive is the method specified by the C standard for 3178providing additional information to the compiler, beyond what is 3179conveyed in the language itself. Three forms of this directive 3180(commonly known as "pragmas") are specified by the 1999 C standard. A 3181C compiler is free to attach any meaning it likes to other pragmas. 3182 3183 GCC has historically preferred to use extensions to the syntax of the 3184language, such as `__attribute__', for this purpose. However, GCC does 3185define a few pragmas of its own. These mostly have effects on the 3186entire translation unit or source file. 3187 3188 In GCC version 3, all GNU-defined, supported pragmas have been given 3189a `GCC' prefix. This is in line with the `STDC' prefix on all pragmas 3190defined by C99. For backward compatibility, pragmas which were 3191recognized by previous versions are still recognized without the `GCC' 3192prefix, but that usage is deprecated. Some older pragmas are 3193deprecated in their entirety. They are not recognized with the `GCC' 3194prefix. *Note Obsolete Features::. 3195 3196 C99 introduces the `_Pragma' operator. This feature addresses a 3197major problem with `#pragma': being a directive, it cannot be produced 3198as the result of macro expansion. `_Pragma' is an operator, much like 3199`sizeof' or `defined', and can be embedded in a macro. 3200 3201 Its syntax is `_Pragma (STRING-LITERAL)', where STRING-LITERAL can 3202be either a normal or wide-character string literal. It is 3203destringized, by replacing all `\\' with a single `\' and all `\"' with 3204a `"'. The result is then processed as if it had appeared as the right 3205hand side of a `#pragma' directive. For example, 3206 3207 _Pragma ("GCC dependency \"parse.y\"") 3208 3209has the same effect as `#pragma GCC dependency "parse.y"'. The same 3210effect could be achieved using macros, for example 3211 3212 #define DO_PRAGMA(x) _Pragma (#x) 3213 DO_PRAGMA (GCC dependency "parse.y") 3214 3215 The standard is unclear on where a `_Pragma' operator can appear. 3216The preprocessor does not accept it within a preprocessing conditional 3217directive like `#if'. To be safe, you are probably best keeping it out 3218of directives other than `#define', and putting it on a line of its own. 3219 3220 This manual documents the pragmas which are meaningful to the 3221preprocessor itself. Other pragmas are meaningful to the C or C++ 3222compilers. They are documented in the GCC manual. 3223 3224 GCC plugins may provide their own pragmas. 3225 3226`#pragma GCC dependency' 3227 `#pragma GCC dependency' allows you to check the relative dates of 3228 the current file and another file. If the other file is more 3229 recent than the current file, a warning is issued. This is useful 3230 if the current file is derived from the other file, and should be 3231 regenerated. The other file is searched for using the normal 3232 include search path. Optional trailing text can be used to give 3233 more information in the warning message. 3234 3235 #pragma GCC dependency "parse.y" 3236 #pragma GCC dependency "/usr/include/time.h" rerun fixincludes 3237 3238`#pragma GCC poison' 3239 Sometimes, there is an identifier that you want to remove 3240 completely from your program, and make sure that it never creeps 3241 back in. To enforce this, you can "poison" the identifier with 3242 this pragma. `#pragma GCC poison' is followed by a list of 3243 identifiers to poison. If any of those identifiers appears 3244 anywhere in the source after the directive, it is a hard error. 3245 For example, 3246 3247 #pragma GCC poison printf sprintf fprintf 3248 sprintf(some_string, "hello"); 3249 3250 will produce an error. 3251 3252 If a poisoned identifier appears as part of the expansion of a 3253 macro which was defined before the identifier was poisoned, it 3254 will _not_ cause an error. This lets you poison an identifier 3255 without worrying about system headers defining macros that use it. 3256 3257 For example, 3258 3259 #define strrchr rindex 3260 #pragma GCC poison rindex 3261 strrchr(some_string, 'h'); 3262 3263 will not produce an error. 3264 3265`#pragma GCC system_header' 3266 This pragma takes no arguments. It causes the rest of the code in 3267 the current file to be treated as if it came from a system header. 3268 *Note System Headers::. 3269 3270 3271 3272File: cpp.info, Node: Other Directives, Next: Preprocessor Output, Prev: Pragmas, Up: Top 3273 32748 Other Directives 3275****************** 3276 3277The `#ident' directive takes one argument, a string constant. On some 3278systems, that string constant is copied into a special segment of the 3279object file. On other systems, the directive is ignored. The `#sccs' 3280directive is a synonym for `#ident'. 3281 3282 These directives are not part of the C standard, but they are not 3283official GNU extensions either. What historical information we have 3284been able to find, suggests they originated with System V. 3285 3286 The "null directive" consists of a `#' followed by a newline, with 3287only whitespace (including comments) in between. A null directive is 3288understood as a preprocessing directive but has no effect on the 3289preprocessor output. The primary significance of the existence of the 3290null directive is that an input line consisting of just a `#' will 3291produce no output, rather than a line of output containing just a `#'. 3292Supposedly some old C programs contain such lines. 3293 3294 3295File: cpp.info, Node: Preprocessor Output, Next: Traditional Mode, Prev: Other Directives, Up: Top 3296 32979 Preprocessor Output 3298********************* 3299 3300When the C preprocessor is used with the C, C++, or Objective-C 3301compilers, it is integrated into the compiler and communicates a stream 3302of binary tokens directly to the compiler's parser. However, it can 3303also be used in the more conventional standalone mode, where it produces 3304textual output. 3305 3306 The output from the C preprocessor looks much like the input, except 3307that all preprocessing directive lines have been replaced with blank 3308lines and all comments with spaces. Long runs of blank lines are 3309discarded. 3310 3311 The ISO standard specifies that it is implementation defined whether 3312a preprocessor preserves whitespace between tokens, or replaces it with 3313e.g. a single space. In GNU CPP, whitespace between tokens is collapsed 3314to become a single space, with the exception that the first token on a 3315non-directive line is preceded with sufficient spaces that it appears in 3316the same column in the preprocessed output that it appeared in the 3317original source file. This is so the output is easy to read. *Note 3318Differences from previous versions::. CPP does not insert any 3319whitespace where there was none in the original source, except where 3320necessary to prevent an accidental token paste. 3321 3322 Source file name and line number information is conveyed by lines of 3323the form 3324 3325 # LINENUM FILENAME FLAGS 3326 3327These are called "linemarkers". They are inserted as needed into the 3328output (but never within a string or character constant). They mean 3329that the following line originated in file FILENAME at line LINENUM. 3330FILENAME will never contain any non-printing characters; they are 3331replaced with octal escape sequences. 3332 3333 After the file name comes zero or more flags, which are `1', `2', 3334`3', or `4'. If there are multiple flags, spaces separate them. Here 3335is what the flags mean: 3336 3337`1' 3338 This indicates the start of a new file. 3339 3340`2' 3341 This indicates returning to a file (after having included another 3342 file). 3343 3344`3' 3345 This indicates that the following text comes from a system header 3346 file, so certain warnings should be suppressed. 3347 3348`4' 3349 This indicates that the following text should be treated as being 3350 wrapped in an implicit `extern "C"' block. 3351 3352 As an extension, the preprocessor accepts linemarkers in 3353non-assembler input files. They are treated like the corresponding 3354`#line' directive, (*note Line Control::), except that trailing flags 3355are permitted, and are interpreted with the meanings described above. 3356If multiple flags are given, they must be in ascending order. 3357 3358 Some directives may be duplicated in the output of the preprocessor. 3359These are `#ident' (always), `#pragma' (only if the preprocessor does 3360not handle the pragma itself), and `#define' and `#undef' (with certain 3361debugging options). If this happens, the `#' of the directive will 3362always be in the first column, and there will be no space between the 3363`#' and the directive name. If macro expansion happens to generate 3364tokens which might be mistaken for a duplicated directive, a space will 3365be inserted between the `#' and the directive name. 3366 3367 3368File: cpp.info, Node: Traditional Mode, Next: Implementation Details, Prev: Preprocessor Output, Up: Top 3369 337010 Traditional Mode 3371******************* 3372 3373Traditional (pre-standard) C preprocessing is rather different from the 3374preprocessing specified by the standard. When GCC is given the 3375`-traditional-cpp' option, it attempts to emulate a traditional 3376preprocessor. 3377 3378 GCC versions 3.2 and later only support traditional mode semantics in 3379the preprocessor, and not in the compiler front ends. This chapter 3380outlines the traditional preprocessor semantics we implemented. 3381 3382 The implementation does not correspond precisely to the behavior of 3383earlier versions of GCC, nor to any true traditional preprocessor. 3384After all, inconsistencies among traditional implementations were a 3385major motivation for C standardization. However, we intend that it 3386should be compatible with true traditional preprocessors in all ways 3387that actually matter. 3388 3389* Menu: 3390 3391* Traditional lexical analysis:: 3392* Traditional macros:: 3393* Traditional miscellany:: 3394* Traditional warnings:: 3395 3396 3397File: cpp.info, Node: Traditional lexical analysis, Next: Traditional macros, Up: Traditional Mode 3398 339910.1 Traditional lexical analysis 3400================================= 3401 3402The traditional preprocessor does not decompose its input into tokens 3403the same way a standards-conforming preprocessor does. The input is 3404simply treated as a stream of text with minimal internal form. 3405 3406 This implementation does not treat trigraphs (*note trigraphs::) 3407specially since they were an invention of the standards committee. It 3408handles arbitrarily-positioned escaped newlines properly and splices 3409the lines as you would expect; many traditional preprocessors did not 3410do this. 3411 3412 The form of horizontal whitespace in the input file is preserved in 3413the output. In particular, hard tabs remain hard tabs. This can be 3414useful if, for example, you are preprocessing a Makefile. 3415 3416 Traditional CPP only recognizes C-style block comments, and treats 3417the `/*' sequence as introducing a comment only if it lies outside 3418quoted text. Quoted text is introduced by the usual single and double 3419quotes, and also by an initial `<' in a `#include' directive. 3420 3421 Traditionally, comments are completely removed and are not replaced 3422with a space. Since a traditional compiler does its own tokenization 3423of the output of the preprocessor, this means that comments can 3424effectively be used as token paste operators. However, comments behave 3425like separators for text handled by the preprocessor itself, since it 3426doesn't re-lex its input. For example, in 3427 3428 #if foo/**/bar 3429 3430`foo' and `bar' are distinct identifiers and expanded separately if 3431they happen to be macros. In other words, this directive is equivalent 3432to 3433 3434 #if foo bar 3435 3436rather than 3437 3438 #if foobar 3439 3440 Generally speaking, in traditional mode an opening quote need not 3441have a matching closing quote. In particular, a macro may be defined 3442with replacement text that contains an unmatched quote. Of course, if 3443you attempt to compile preprocessed output containing an unmatched quote 3444you will get a syntax error. 3445 3446 However, all preprocessing directives other than `#define' require 3447matching quotes. For example: 3448 3449 #define m This macro's fine and has an unmatched quote 3450 "/* This is not a comment. */ 3451 /* This is a comment. The following #include directive 3452 is ill-formed. */ 3453 #include <stdio.h 3454 3455 Just as for the ISO preprocessor, what would be a closing quote can 3456be escaped with a backslash to prevent the quoted text from closing. 3457 3458 3459File: cpp.info, Node: Traditional macros, Next: Traditional miscellany, Prev: Traditional lexical analysis, Up: Traditional Mode 3460 346110.2 Traditional macros 3462======================= 3463 3464The major difference between traditional and ISO macros is that the 3465former expand to text rather than to a token sequence. CPP removes all 3466leading and trailing horizontal whitespace from a macro's replacement 3467text before storing it, but preserves the form of internal whitespace. 3468 3469 One consequence is that it is legitimate for the replacement text to 3470contain an unmatched quote (*note Traditional lexical analysis::). An 3471unclosed string or character constant continues into the text following 3472the macro call. Similarly, the text at the end of a macro's expansion 3473can run together with the text after the macro invocation to produce a 3474single token. 3475 3476 Normally comments are removed from the replacement text after the 3477macro is expanded, but if the `-CC' option is passed on the command 3478line comments are preserved. (In fact, the current implementation 3479removes comments even before saving the macro replacement text, but it 3480careful to do it in such a way that the observed effect is identical 3481even in the function-like macro case.) 3482 3483 The ISO stringification operator `#' and token paste operator `##' 3484have no special meaning. As explained later, an effect similar to 3485these operators can be obtained in a different way. Macro names that 3486are embedded in quotes, either from the main file or after macro 3487replacement, do not expand. 3488 3489 CPP replaces an unquoted object-like macro name with its replacement 3490text, and then rescans it for further macros to replace. Unlike 3491standard macro expansion, traditional macro expansion has no provision 3492to prevent recursion. If an object-like macro appears unquoted in its 3493replacement text, it will be replaced again during the rescan pass, and 3494so on _ad infinitum_. GCC detects when it is expanding recursive 3495macros, emits an error message, and continues after the offending macro 3496invocation. 3497 3498 #define PLUS + 3499 #define INC(x) PLUS+x 3500 INC(foo); 3501 ==> ++foo; 3502 3503 Function-like macros are similar in form but quite different in 3504behavior to their ISO counterparts. Their arguments are contained 3505within parentheses, are comma-separated, and can cross physical lines. 3506Commas within nested parentheses are not treated as argument 3507separators. Similarly, a quote in an argument cannot be left unclosed; 3508a following comma or parenthesis that comes before the closing quote is 3509treated like any other character. There is no facility for handling 3510variadic macros. 3511 3512 This implementation removes all comments from macro arguments, unless 3513the `-C' option is given. The form of all other horizontal whitespace 3514in arguments is preserved, including leading and trailing whitespace. 3515In particular 3516 3517 f( ) 3518 3519is treated as an invocation of the macro `f' with a single argument 3520consisting of a single space. If you want to invoke a function-like 3521macro that takes no arguments, you must not leave any whitespace 3522between the parentheses. 3523 3524 If a macro argument crosses a new line, the new line is replaced with 3525a space when forming the argument. If the previous line contained an 3526unterminated quote, the following line inherits the quoted state. 3527 3528 Traditional preprocessors replace parameters in the replacement text 3529with their arguments regardless of whether the parameters are within 3530quotes or not. This provides a way to stringize arguments. For example 3531 3532 #define str(x) "x" 3533 str(/* A comment */some text ) 3534 ==> "some text " 3535 3536Note that the comment is removed, but that the trailing space is 3537preserved. Here is an example of using a comment to effect token 3538pasting. 3539 3540 #define suffix(x) foo_/**/x 3541 suffix(bar) 3542 ==> foo_bar 3543 3544 3545File: cpp.info, Node: Traditional miscellany, Next: Traditional warnings, Prev: Traditional macros, Up: Traditional Mode 3546 354710.3 Traditional miscellany 3548=========================== 3549 3550Here are some things to be aware of when using the traditional 3551preprocessor. 3552 3553 * Preprocessing directives are recognized only when their leading 3554 `#' appears in the first column. There can be no whitespace 3555 between the beginning of the line and the `#', but whitespace can 3556 follow the `#'. 3557 3558 * A true traditional C preprocessor does not recognize `#error' or 3559 `#pragma', and may not recognize `#elif'. CPP supports all the 3560 directives in traditional mode that it supports in ISO mode, 3561 including extensions, with the exception that the effects of 3562 `#pragma GCC poison' are undefined. 3563 3564 * __STDC__ is not defined. 3565 3566 * If you use digraphs the behavior is undefined. 3567 3568 * If a line that looks like a directive appears within macro 3569 arguments, the behavior is undefined. 3570 3571 3572 3573File: cpp.info, Node: Traditional warnings, Prev: Traditional miscellany, Up: Traditional Mode 3574 357510.4 Traditional warnings 3576========================= 3577 3578You can request warnings about features that did not exist, or worked 3579differently, in traditional C with the `-Wtraditional' option. GCC 3580does not warn about features of ISO C which you must use when you are 3581using a conforming compiler, such as the `#' and `##' operators. 3582 3583 Presently `-Wtraditional' warns about: 3584 3585 * Macro parameters that appear within string literals in the macro 3586 body. In traditional C macro replacement takes place within 3587 string literals, but does not in ISO C. 3588 3589 * In traditional C, some preprocessor directives did not exist. 3590 Traditional preprocessors would only consider a line to be a 3591 directive if the `#' appeared in column 1 on the line. Therefore 3592 `-Wtraditional' warns about directives that traditional C 3593 understands but would ignore because the `#' does not appear as the 3594 first character on the line. It also suggests you hide directives 3595 like `#pragma' not understood by traditional C by indenting them. 3596 Some traditional implementations would not recognize `#elif', so it 3597 suggests avoiding it altogether. 3598 3599 * A function-like macro that appears without an argument list. In 3600 some traditional preprocessors this was an error. In ISO C it 3601 merely means that the macro is not expanded. 3602 3603 * The unary plus operator. This did not exist in traditional C. 3604 3605 * The `U' and `LL' integer constant suffixes, which were not 3606 available in traditional C. (Traditional C does support the `L' 3607 suffix for simple long integer constants.) You are not warned 3608 about uses of these suffixes in macros defined in system headers. 3609 For instance, `UINT_MAX' may well be defined as `4294967295U', but 3610 you will not be warned if you use `UINT_MAX'. 3611 3612 You can usually avoid the warning, and the related warning about 3613 constants which are so large that they are unsigned, by writing the 3614 integer constant in question in hexadecimal, with no U suffix. 3615 Take care, though, because this gives the wrong result in exotic 3616 cases. 3617 3618 3619File: cpp.info, Node: Implementation Details, Next: Invocation, Prev: Traditional Mode, Up: Top 3620 362111 Implementation Details 3622************************* 3623 3624Here we document details of how the preprocessor's implementation 3625affects its user-visible behavior. You should try to avoid undue 3626reliance on behavior described here, as it is possible that it will 3627change subtly in future implementations. 3628 3629 Also documented here are obsolete features and changes from previous 3630versions of CPP. 3631 3632* Menu: 3633 3634* Implementation-defined behavior:: 3635* Implementation limits:: 3636* Obsolete Features:: 3637* Differences from previous versions:: 3638 3639 3640File: cpp.info, Node: Implementation-defined behavior, Next: Implementation limits, Up: Implementation Details 3641 364211.1 Implementation-defined behavior 3643==================================== 3644 3645This is how CPP behaves in all the cases which the C standard describes 3646as "implementation-defined". This term means that the implementation 3647is free to do what it likes, but must document its choice and stick to 3648it. 3649 3650 * The mapping of physical source file multi-byte characters to the 3651 execution character set. 3652 3653 The input character set can be specified using the 3654 `-finput-charset' option, while the execution character set may be 3655 controlled using the `-fexec-charset' and `-fwide-exec-charset' 3656 options. 3657 3658 * Identifier characters. 3659 3660 The C and C++ standards allow identifiers to be composed of `_' 3661 and the alphanumeric characters. C++ and C99 also allow universal 3662 character names, and C99 further permits implementation-defined 3663 characters. GCC currently only permits universal character names 3664 if `-fextended-identifiers' is used, because the implementation of 3665 universal character names in identifiers is experimental. 3666 3667 GCC allows the `$' character in identifiers as an extension for 3668 most targets. This is true regardless of the `std=' switch, since 3669 this extension cannot conflict with standards-conforming programs. 3670 When preprocessing assembler, however, dollars are not identifier 3671 characters by default. 3672 3673 Currently the targets that by default do not permit `$' are AVR, 3674 IP2K, MMIX, MIPS Irix 3, ARM aout, and PowerPC targets for the AIX 3675 operating system. 3676 3677 You can override the default with `-fdollars-in-identifiers' or 3678 `fno-dollars-in-identifiers'. *Note fdollars-in-identifiers::. 3679 3680 * Non-empty sequences of whitespace characters. 3681 3682 In textual output, each whitespace sequence is collapsed to a 3683 single space. For aesthetic reasons, the first token on each 3684 non-directive line of output is preceded with sufficient spaces 3685 that it appears in the same column as it did in the original 3686 source file. 3687 3688 * The numeric value of character constants in preprocessor 3689 expressions. 3690 3691 The preprocessor and compiler interpret character constants in the 3692 same way; i.e. escape sequences such as `\a' are given the values 3693 they would have on the target machine. 3694 3695 The compiler evaluates a multi-character character constant a 3696 character at a time, shifting the previous value left by the 3697 number of bits per target character, and then or-ing in the 3698 bit-pattern of the new character truncated to the width of a 3699 target character. The final bit-pattern is given type `int', and 3700 is therefore signed, regardless of whether single characters are 3701 signed or not (a slight change from versions 3.1 and earlier of 3702 GCC). If there are more characters in the constant than would fit 3703 in the target `int' the compiler issues a warning, and the excess 3704 leading characters are ignored. 3705 3706 For example, `'ab'' for a target with an 8-bit `char' would be 3707 interpreted as 3708 `(int) ((unsigned char) 'a' * 256 + (unsigned char) 'b')', and 3709 `'\234a'' as 3710 `(int) ((unsigned char) '\234' * 256 + (unsigned char) 'a')'. 3711 3712 * Source file inclusion. 3713 3714 For a discussion on how the preprocessor locates header files, 3715 *Note Include Operation::. 3716 3717 * Interpretation of the filename resulting from a macro-expanded 3718 `#include' directive. 3719 3720 *Note Computed Includes::. 3721 3722 * Treatment of a `#pragma' directive that after macro-expansion 3723 results in a standard pragma. 3724 3725 No macro expansion occurs on any `#pragma' directive line, so the 3726 question does not arise. 3727 3728 Note that GCC does not yet implement any of the standard pragmas. 3729 3730 3731 3732File: cpp.info, Node: Implementation limits, Next: Obsolete Features, Prev: Implementation-defined behavior, Up: Implementation Details 3733 373411.2 Implementation limits 3735========================== 3736 3737CPP has a small number of internal limits. This section lists the 3738limits which the C standard requires to be no lower than some minimum, 3739and all the others known. It is intended that there should be as few 3740limits as possible. If you encounter an undocumented or inconvenient 3741limit, please report that as a bug. *Note Reporting Bugs: (gcc)Bugs. 3742 3743 Where we say something is limited "only by available memory", that 3744means that internal data structures impose no intrinsic limit, and space 3745is allocated with `malloc' or equivalent. The actual limit will 3746therefore depend on many things, such as the size of other things 3747allocated by the compiler at the same time, the amount of memory 3748consumed by other processes on the same computer, etc. 3749 3750 * Nesting levels of `#include' files. 3751 3752 We impose an arbitrary limit of 200 levels, to avoid runaway 3753 recursion. The standard requires at least 15 levels. 3754 3755 * Nesting levels of conditional inclusion. 3756 3757 The C standard mandates this be at least 63. CPP is limited only 3758 by available memory. 3759 3760 * Levels of parenthesized expressions within a full expression. 3761 3762 The C standard requires this to be at least 63. In preprocessor 3763 conditional expressions, it is limited only by available memory. 3764 3765 * Significant initial characters in an identifier or macro name. 3766 3767 The preprocessor treats all characters as significant. The C 3768 standard requires only that the first 63 be significant. 3769 3770 * Number of macros simultaneously defined in a single translation 3771 unit. 3772 3773 The standard requires at least 4095 be possible. CPP is limited 3774 only by available memory. 3775 3776 * Number of parameters in a macro definition and arguments in a 3777 macro call. 3778 3779 We allow `USHRT_MAX', which is no smaller than 65,535. The minimum 3780 required by the standard is 127. 3781 3782 * Number of characters on a logical source line. 3783 3784 The C standard requires a minimum of 4096 be permitted. CPP places 3785 no limits on this, but you may get incorrect column numbers 3786 reported in diagnostics for lines longer than 65,535 characters. 3787 3788 * Maximum size of a source file. 3789 3790 The standard does not specify any lower limit on the maximum size 3791 of a source file. GNU cpp maps files into memory, so it is 3792 limited by the available address space. This is generally at 3793 least two gigabytes. Depending on the operating system, the size 3794 of physical memory may or may not be a limitation. 3795 3796 3797 3798File: cpp.info, Node: Obsolete Features, Next: Differences from previous versions, Prev: Implementation limits, Up: Implementation Details 3799 380011.3 Obsolete Features 3801====================== 3802 3803CPP has some features which are present mainly for compatibility with 3804older programs. We discourage their use in new code. In some cases, 3805we plan to remove the feature in a future version of GCC. 3806 380711.3.1 Assertions 3808----------------- 3809 3810"Assertions" are a deprecated alternative to macros in writing 3811conditionals to test what sort of computer or system the compiled 3812program will run on. Assertions are usually predefined, but you can 3813define them with preprocessing directives or command-line options. 3814 3815 Assertions were intended to provide a more systematic way to describe 3816the compiler's target system and we added them for compatibility with 3817existing compilers. In practice they are just as unpredictable as the 3818system-specific predefined macros. In addition, they are not part of 3819any standard, and only a few compilers support them. Therefore, the 3820use of assertions is *less* portable than the use of system-specific 3821predefined macros. We recommend you do not use them at all. 3822 3823 An assertion looks like this: 3824 3825 #PREDICATE (ANSWER) 3826 3827PREDICATE must be a single identifier. ANSWER can be any sequence of 3828tokens; all characters are significant except for leading and trailing 3829whitespace, and differences in internal whitespace sequences are 3830ignored. (This is similar to the rules governing macro redefinition.) 3831Thus, `(x + y)' is different from `(x+y)' but equivalent to 3832`( x + y )'. Parentheses do not nest inside an answer. 3833 3834 To test an assertion, you write it in an `#if'. For example, this 3835conditional succeeds if either `vax' or `ns16000' has been asserted as 3836an answer for `machine'. 3837 3838 #if #machine (vax) || #machine (ns16000) 3839 3840You can test whether _any_ answer is asserted for a predicate by 3841omitting the answer in the conditional: 3842 3843 #if #machine 3844 3845 Assertions are made with the `#assert' directive. Its sole argument 3846is the assertion to make, without the leading `#' that identifies 3847assertions in conditionals. 3848 3849 #assert PREDICATE (ANSWER) 3850 3851You may make several assertions with the same predicate and different 3852answers. Subsequent assertions do not override previous ones for the 3853same predicate. All the answers for any given predicate are 3854simultaneously true. 3855 3856 Assertions can be canceled with the `#unassert' directive. It has 3857the same syntax as `#assert'. In that form it cancels only the answer 3858which was specified on the `#unassert' line; other answers for that 3859predicate remain true. You can cancel an entire predicate by leaving 3860out the answer: 3861 3862 #unassert PREDICATE 3863 3864In either form, if no such assertion has been made, `#unassert' has no 3865effect. 3866 3867 You can also make or cancel assertions using command line options. 3868*Note Invocation::. 3869 3870 3871File: cpp.info, Node: Differences from previous versions, Prev: Obsolete Features, Up: Implementation Details 3872 387311.4 Differences from previous versions 3874======================================= 3875 3876This section details behavior which has changed from previous versions 3877of CPP. We do not plan to change it again in the near future, but we 3878do not promise not to, either. 3879 3880 The "previous versions" discussed here are 2.95 and before. The 3881behavior of GCC 3.0 is mostly the same as the behavior of the widely 3882used 2.96 and 2.97 development snapshots. Where there are differences, 3883they generally represent bugs in the snapshots. 3884 3885 * -I- deprecated 3886 3887 This option has been deprecated in 4.0. `-iquote' is meant to 3888 replace the need for this option. 3889 3890 * Order of evaluation of `#' and `##' operators 3891 3892 The standard does not specify the order of evaluation of a chain of 3893 `##' operators, nor whether `#' is evaluated before, after, or at 3894 the same time as `##'. You should therefore not write any code 3895 which depends on any specific ordering. It is possible to 3896 guarantee an ordering, if you need one, by suitable use of nested 3897 macros. 3898 3899 An example of where this might matter is pasting the arguments `1', 3900 `e' and `-2'. This would be fine for left-to-right pasting, but 3901 right-to-left pasting would produce an invalid token `e-2'. 3902 3903 GCC 3.0 evaluates `#' and `##' at the same time and strictly left 3904 to right. Older versions evaluated all `#' operators first, then 3905 all `##' operators, in an unreliable order. 3906 3907 * The form of whitespace between tokens in preprocessor output 3908 3909 *Note Preprocessor Output::, for the current textual format. This 3910 is also the format used by stringification. Normally, the 3911 preprocessor communicates tokens directly to the compiler's 3912 parser, and whitespace does not come up at all. 3913 3914 Older versions of GCC preserved all whitespace provided by the 3915 user and inserted lots more whitespace of their own, because they 3916 could not accurately predict when extra spaces were needed to 3917 prevent accidental token pasting. 3918 3919 * Optional argument when invoking rest argument macros 3920 3921 As an extension, GCC permits you to omit the variable arguments 3922 entirely when you use a variable argument macro. This is 3923 forbidden by the 1999 C standard, and will provoke a pedantic 3924 warning with GCC 3.0. Previous versions accepted it silently. 3925 3926 * `##' swallowing preceding text in rest argument macros 3927 3928 Formerly, in a macro expansion, if `##' appeared before a variable 3929 arguments parameter, and the set of tokens specified for that 3930 argument in the macro invocation was empty, previous versions of 3931 CPP would back up and remove the preceding sequence of 3932 non-whitespace characters (*not* the preceding token). This 3933 extension is in direct conflict with the 1999 C standard and has 3934 been drastically pared back. 3935 3936 In the current version of the preprocessor, if `##' appears between 3937 a comma and a variable arguments parameter, and the variable 3938 argument is omitted entirely, the comma will be removed from the 3939 expansion. If the variable argument is empty, or the token before 3940 `##' is not a comma, then `##' behaves as a normal token paste. 3941 3942 * `#line' and `#include' 3943 3944 The `#line' directive used to change GCC's notion of the 3945 "directory containing the current file", used by `#include' with a 3946 double-quoted header file name. In 3.0 and later, it does not. 3947 *Note Line Control::, for further explanation. 3948 3949 * Syntax of `#line' 3950 3951 In GCC 2.95 and previous, the string constant argument to `#line' 3952 was treated the same way as the argument to `#include': backslash 3953 escapes were not honored, and the string ended at the second `"'. 3954 This is not compliant with the C standard. In GCC 3.0, an attempt 3955 was made to correct the behavior, so that the string was treated 3956 as a real string constant, but it turned out to be buggy. In 3.1, 3957 the bugs have been fixed. (We are not fixing the bugs in 3.0 3958 because they affect relatively few people and the fix is quite 3959 invasive.) 3960 3961 3962 3963File: cpp.info, Node: Invocation, Next: Environment Variables, Prev: Implementation Details, Up: Top 3964 396512 Invocation 3966************* 3967 3968Most often when you use the C preprocessor you will not have to invoke 3969it explicitly: the C compiler will do so automatically. However, the 3970preprocessor is sometimes useful on its own. All the options listed 3971here are also acceptable to the C compiler and have the same meaning, 3972except that the C compiler has different rules for specifying the output 3973file. 3974 3975 _Note:_ Whether you use the preprocessor by way of `gcc' or `cpp', 3976the "compiler driver" is run first. This program's purpose is to 3977translate your command into invocations of the programs that do the 3978actual work. Their command line interfaces are similar but not 3979identical to the documented interface, and may change without notice. 3980 3981 The C preprocessor expects two file names as arguments, INFILE and 3982OUTFILE. The preprocessor reads INFILE together with any other files 3983it specifies with `#include'. All the output generated by the combined 3984input files is written in OUTFILE. 3985 3986 Either INFILE or OUTFILE may be `-', which as INFILE means to read 3987from standard input and as OUTFILE means to write to standard output. 3988Also, if either file is omitted, it means the same as if `-' had been 3989specified for that file. 3990 3991 Unless otherwise noted, or the option ends in `=', all options which 3992take an argument may have that argument appear either immediately after 3993the option, or with a space between option and argument: `-Ifoo' and 3994`-I foo' have the same effect. 3995 3996 Many options have multi-letter names; therefore multiple 3997single-letter options may _not_ be grouped: `-dM' is very different from 3998`-d -M'. 3999 4000`-D NAME' 4001 Predefine NAME as a macro, with definition `1'. 4002 4003`-D NAME=DEFINITION' 4004 The contents of DEFINITION are tokenized and processed as if they 4005 appeared during translation phase three in a `#define' directive. 4006 In particular, the definition will be truncated by embedded 4007 newline characters. 4008 4009 If you are invoking the preprocessor from a shell or shell-like 4010 program you may need to use the shell's quoting syntax to protect 4011 characters such as spaces that have a meaning in the shell syntax. 4012 4013 If you wish to define a function-like macro on the command line, 4014 write its argument list with surrounding parentheses before the 4015 equals sign (if any). Parentheses are meaningful to most shells, 4016 so you will need to quote the option. With `sh' and `csh', 4017 `-D'NAME(ARGS...)=DEFINITION'' works. 4018 4019 `-D' and `-U' options are processed in the order they are given on 4020 the command line. All `-imacros FILE' and `-include FILE' options 4021 are processed after all `-D' and `-U' options. 4022 4023`-U NAME' 4024 Cancel any previous definition of NAME, either built in or 4025 provided with a `-D' option. 4026 4027`-undef' 4028 Do not predefine any system-specific or GCC-specific macros. The 4029 standard predefined macros remain defined. *Note Standard 4030 Predefined Macros::. 4031 4032`-I DIR' 4033 Add the directory DIR to the list of directories to be searched 4034 for header files. *Note Search Path::. Directories named by `-I' 4035 are searched before the standard system include directories. If 4036 the directory DIR is a standard system include directory, the 4037 option is ignored to ensure that the default search order for 4038 system directories and the special treatment of system headers are 4039 not defeated (*note System Headers::) . If DIR begins with `=', 4040 then the `=' will be replaced by the sysroot prefix; see 4041 `--sysroot' and `-isysroot'. 4042 4043`-o FILE' 4044 Write output to FILE. This is the same as specifying FILE as the 4045 second non-option argument to `cpp'. `gcc' has a different 4046 interpretation of a second non-option argument, so you must use 4047 `-o' to specify the output file. 4048 4049`-Wall' 4050 Turns on all optional warnings which are desirable for normal code. 4051 At present this is `-Wcomment', `-Wtrigraphs', `-Wmultichar' and a 4052 warning about integer promotion causing a change of sign in `#if' 4053 expressions. Note that many of the preprocessor's warnings are on 4054 by default and have no options to control them. 4055 4056`-Wcomment' 4057`-Wcomments' 4058 Warn whenever a comment-start sequence `/*' appears in a `/*' 4059 comment, or whenever a backslash-newline appears in a `//' comment. 4060 (Both forms have the same effect.) 4061 4062`-Wtrigraphs' 4063 Most trigraphs in comments cannot affect the meaning of the 4064 program. However, a trigraph that would form an escaped newline 4065 (`??/' at the end of a line) can, by changing where the comment 4066 begins or ends. Therefore, only trigraphs that would form escaped 4067 newlines produce warnings inside a comment. 4068 4069 This option is implied by `-Wall'. If `-Wall' is not given, this 4070 option is still enabled unless trigraphs are enabled. To get 4071 trigraph conversion without warnings, but get the other `-Wall' 4072 warnings, use `-trigraphs -Wall -Wno-trigraphs'. 4073 4074`-Wtraditional' 4075 Warn about certain constructs that behave differently in 4076 traditional and ISO C. Also warn about ISO C constructs that have 4077 no traditional C equivalent, and problematic constructs which 4078 should be avoided. *Note Traditional Mode::. 4079 4080`-Wundef' 4081 Warn whenever an identifier which is not a macro is encountered in 4082 an `#if' directive, outside of `defined'. Such identifiers are 4083 replaced with zero. 4084 4085`-Wunused-macros' 4086 Warn about macros defined in the main file that are unused. A 4087 macro is "used" if it is expanded or tested for existence at least 4088 once. The preprocessor will also warn if the macro has not been 4089 used at the time it is redefined or undefined. 4090 4091 Built-in macros, macros defined on the command line, and macros 4092 defined in include files are not warned about. 4093 4094 _Note:_ If a macro is actually used, but only used in skipped 4095 conditional blocks, then CPP will report it as unused. To avoid 4096 the warning in such a case, you might improve the scope of the 4097 macro's definition by, for example, moving it into the first 4098 skipped block. Alternatively, you could provide a dummy use with 4099 something like: 4100 4101 #if defined the_macro_causing_the_warning 4102 #endif 4103 4104`-Wendif-labels' 4105 Warn whenever an `#else' or an `#endif' are followed by text. 4106 This usually happens in code of the form 4107 4108 #if FOO 4109 ... 4110 #else FOO 4111 ... 4112 #endif FOO 4113 4114 The second and third `FOO' should be in comments, but often are not 4115 in older programs. This warning is on by default. 4116 4117`-Werror' 4118 Make all warnings into hard errors. Source code which triggers 4119 warnings will be rejected. 4120 4121`-Wsystem-headers' 4122 Issue warnings for code in system headers. These are normally 4123 unhelpful in finding bugs in your own code, therefore suppressed. 4124 If you are responsible for the system library, you may want to see 4125 them. 4126 4127`-w' 4128 Suppress all warnings, including those which GNU CPP issues by 4129 default. 4130 4131`-pedantic' 4132 Issue all the mandatory diagnostics listed in the C standard. 4133 Some of them are left out by default, since they trigger 4134 frequently on harmless code. 4135 4136`-pedantic-errors' 4137 Issue all the mandatory diagnostics, and make all mandatory 4138 diagnostics into errors. This includes mandatory diagnostics that 4139 GCC issues without `-pedantic' but treats as warnings. 4140 4141`-M' 4142 Instead of outputting the result of preprocessing, output a rule 4143 suitable for `make' describing the dependencies of the main source 4144 file. The preprocessor outputs one `make' rule containing the 4145 object file name for that source file, a colon, and the names of 4146 all the included files, including those coming from `-include' or 4147 `-imacros' command line options. 4148 4149 Unless specified explicitly (with `-MT' or `-MQ'), the object file 4150 name consists of the name of the source file with any suffix 4151 replaced with object file suffix and with any leading directory 4152 parts removed. If there are many included files then the rule is 4153 split into several lines using `\'-newline. The rule has no 4154 commands. 4155 4156 This option does not suppress the preprocessor's debug output, 4157 such as `-dM'. To avoid mixing such debug output with the 4158 dependency rules you should explicitly specify the dependency 4159 output file with `-MF', or use an environment variable like 4160 `DEPENDENCIES_OUTPUT' (*note Environment Variables::). Debug 4161 output will still be sent to the regular output stream as normal. 4162 4163 Passing `-M' to the driver implies `-E', and suppresses warnings 4164 with an implicit `-w'. 4165 4166`-MM' 4167 Like `-M' but do not mention header files that are found in system 4168 header directories, nor header files that are included, directly 4169 or indirectly, from such a header. 4170 4171 This implies that the choice of angle brackets or double quotes in 4172 an `#include' directive does not in itself determine whether that 4173 header will appear in `-MM' dependency output. This is a slight 4174 change in semantics from GCC versions 3.0 and earlier. 4175 4176`-MF FILE' 4177 When used with `-M' or `-MM', specifies a file to write the 4178 dependencies to. If no `-MF' switch is given the preprocessor 4179 sends the rules to the same place it would have sent preprocessed 4180 output. 4181 4182 When used with the driver options `-MD' or `-MMD', `-MF' overrides 4183 the default dependency output file. 4184 4185`-MG' 4186 In conjunction with an option such as `-M' requesting dependency 4187 generation, `-MG' assumes missing header files are generated files 4188 and adds them to the dependency list without raising an error. 4189 The dependency filename is taken directly from the `#include' 4190 directive without prepending any path. `-MG' also suppresses 4191 preprocessed output, as a missing header file renders this useless. 4192 4193 This feature is used in automatic updating of makefiles. 4194 4195`-MP' 4196 This option instructs CPP to add a phony target for each dependency 4197 other than the main file, causing each to depend on nothing. These 4198 dummy rules work around errors `make' gives if you remove header 4199 files without updating the `Makefile' to match. 4200 4201 This is typical output: 4202 4203 test.o: test.c test.h 4204 4205 test.h: 4206 4207`-MT TARGET' 4208 Change the target of the rule emitted by dependency generation. By 4209 default CPP takes the name of the main input file, deletes any 4210 directory components and any file suffix such as `.c', and appends 4211 the platform's usual object suffix. The result is the target. 4212 4213 An `-MT' option will set the target to be exactly the string you 4214 specify. If you want multiple targets, you can specify them as a 4215 single argument to `-MT', or use multiple `-MT' options. 4216 4217 For example, `-MT '$(objpfx)foo.o'' might give 4218 4219 $(objpfx)foo.o: foo.c 4220 4221`-MQ TARGET' 4222 Same as `-MT', but it quotes any characters which are special to 4223 Make. `-MQ '$(objpfx)foo.o'' gives 4224 4225 $$(objpfx)foo.o: foo.c 4226 4227 The default target is automatically quoted, as if it were given 4228 with `-MQ'. 4229 4230`-MD' 4231 `-MD' is equivalent to `-M -MF FILE', except that `-E' is not 4232 implied. The driver determines FILE based on whether an `-o' 4233 option is given. If it is, the driver uses its argument but with 4234 a suffix of `.d', otherwise it takes the name of the input file, 4235 removes any directory components and suffix, and applies a `.d' 4236 suffix. 4237 4238 If `-MD' is used in conjunction with `-E', any `-o' switch is 4239 understood to specify the dependency output file (*note -MF: 4240 dashMF.), but if used without `-E', each `-o' is understood to 4241 specify a target object file. 4242 4243 Since `-E' is not implied, `-MD' can be used to generate a 4244 dependency output file as a side-effect of the compilation process. 4245 4246`-MMD' 4247 Like `-MD' except mention only user header files, not system 4248 header files. 4249 4250`-x c' 4251`-x c++' 4252`-x objective-c' 4253`-x assembler-with-cpp' 4254 Specify the source language: C, C++, Objective-C, or assembly. 4255 This has nothing to do with standards conformance or extensions; 4256 it merely selects which base syntax to expect. If you give none 4257 of these options, cpp will deduce the language from the extension 4258 of the source file: `.c', `.cc', `.m', or `.S'. Some other common 4259 extensions for C++ and assembly are also recognized. If cpp does 4260 not recognize the extension, it will treat the file as C; this is 4261 the most generic mode. 4262 4263 _Note:_ Previous versions of cpp accepted a `-lang' option which 4264 selected both the language and the standards conformance level. 4265 This option has been removed, because it conflicts with the `-l' 4266 option. 4267 4268`-std=STANDARD' 4269`-ansi' 4270 Specify the standard to which the code should conform. Currently 4271 CPP knows about C and C++ standards; others may be added in the 4272 future. 4273 4274 STANDARD may be one of: 4275 `c90' 4276 `c89' 4277 `iso9899:1990' 4278 The ISO C standard from 1990. `c90' is the customary 4279 shorthand for this version of the standard. 4280 4281 The `-ansi' option is equivalent to `-std=c90'. 4282 4283 `iso9899:199409' 4284 The 1990 C standard, as amended in 1994. 4285 4286 `iso9899:1999' 4287 `c99' 4288 `iso9899:199x' 4289 `c9x' 4290 The revised ISO C standard, published in December 1999. 4291 Before publication, this was known as C9X. 4292 4293 `gnu90' 4294 `gnu89' 4295 The 1990 C standard plus GNU extensions. This is the default. 4296 4297 `gnu99' 4298 `gnu9x' 4299 The 1999 C standard plus GNU extensions. 4300 4301 `c++98' 4302 The 1998 ISO C++ standard plus amendments. 4303 4304 `gnu++98' 4305 The same as `-std=c++98' plus GNU extensions. This is the 4306 default for C++ code. 4307 4308`-I-' 4309 Split the include path. Any directories specified with `-I' 4310 options before `-I-' are searched only for headers requested with 4311 `#include "FILE"'; they are not searched for `#include <FILE>'. 4312 If additional directories are specified with `-I' options after 4313 the `-I-', those directories are searched for all `#include' 4314 directives. 4315 4316 In addition, `-I-' inhibits the use of the directory of the current 4317 file directory as the first search directory for `#include "FILE"'. 4318 *Note Search Path::. This option has been deprecated. 4319 4320`-nostdinc' 4321 Do not search the standard system directories for header files. 4322 Only the directories you have specified with `-I' options (and the 4323 directory of the current file, if appropriate) are searched. 4324 4325`-nostdinc++' 4326 Do not search for header files in the C++-specific standard 4327 directories, but do still search the other standard directories. 4328 (This option is used when building the C++ library.) 4329 4330`-include FILE' 4331 Process FILE as if `#include "file"' appeared as the first line of 4332 the primary source file. However, the first directory searched 4333 for FILE is the preprocessor's working directory _instead of_ the 4334 directory containing the main source file. If not found there, it 4335 is searched for in the remainder of the `#include "..."' search 4336 chain as normal. 4337 4338 If multiple `-include' options are given, the files are included 4339 in the order they appear on the command line. 4340 4341`-imacros FILE' 4342 Exactly like `-include', except that any output produced by 4343 scanning FILE is thrown away. Macros it defines remain defined. 4344 This allows you to acquire all the macros from a header without 4345 also processing its declarations. 4346 4347 All files specified by `-imacros' are processed before all files 4348 specified by `-include'. 4349 4350`-idirafter DIR' 4351 Search DIR for header files, but do it _after_ all directories 4352 specified with `-I' and the standard system directories have been 4353 exhausted. DIR is treated as a system include directory. If DIR 4354 begins with `=', then the `=' will be replaced by the sysroot 4355 prefix; see `--sysroot' and `-isysroot'. 4356 4357`-iprefix PREFIX' 4358 Specify PREFIX as the prefix for subsequent `-iwithprefix' 4359 options. If the prefix represents a directory, you should include 4360 the final `/'. 4361 4362`-iwithprefix DIR' 4363`-iwithprefixbefore DIR' 4364 Append DIR to the prefix specified previously with `-iprefix', and 4365 add the resulting directory to the include search path. 4366 `-iwithprefixbefore' puts it in the same place `-I' would; 4367 `-iwithprefix' puts it where `-idirafter' would. 4368 4369`-isysroot DIR' 4370 This option is like the `--sysroot' option, but applies only to 4371 header files. See the `--sysroot' option for more information. 4372 4373`-imultilib DIR' 4374 Use DIR as a subdirectory of the directory containing 4375 target-specific C++ headers. 4376 4377`-isystem DIR' 4378 Search DIR for header files, after all directories specified by 4379 `-I' but before the standard system directories. Mark it as a 4380 system directory, so that it gets the same special treatment as is 4381 applied to the standard system directories. *Note System 4382 Headers::. If DIR begins with `=', then the `=' will be replaced 4383 by the sysroot prefix; see `--sysroot' and `-isysroot'. 4384 4385`-iquote DIR' 4386 Search DIR only for header files requested with `#include "FILE"'; 4387 they are not searched for `#include <FILE>', before all 4388 directories specified by `-I' and before the standard system 4389 directories. *Note Search Path::. If DIR begins with `=', then 4390 the `=' will be replaced by the sysroot prefix; see `--sysroot' 4391 and `-isysroot'. 4392 4393`-fdirectives-only' 4394 When preprocessing, handle directives, but do not expand macros. 4395 4396 The option's behavior depends on the `-E' and `-fpreprocessed' 4397 options. 4398 4399 With `-E', preprocessing is limited to the handling of directives 4400 such as `#define', `#ifdef', and `#error'. Other preprocessor 4401 operations, such as macro expansion and trigraph conversion are 4402 not performed. In addition, the `-dD' option is implicitly 4403 enabled. 4404 4405 With `-fpreprocessed', predefinition of command line and most 4406 builtin macros is disabled. Macros such as `__LINE__', which are 4407 contextually dependent, are handled normally. This enables 4408 compilation of files previously preprocessed with `-E 4409 -fdirectives-only'. 4410 4411 With both `-E' and `-fpreprocessed', the rules for 4412 `-fpreprocessed' take precedence. This enables full preprocessing 4413 of files previously preprocessed with `-E -fdirectives-only'. 4414 4415`-fdollars-in-identifiers' 4416 Accept `$' in identifiers. *Note Identifier characters::. 4417 4418`-fextended-identifiers' 4419 Accept universal character names in identifiers. This option is 4420 experimental; in a future version of GCC, it will be enabled by 4421 default for C99 and C++. 4422 4423`-fpreprocessed' 4424 Indicate to the preprocessor that the input file has already been 4425 preprocessed. This suppresses things like macro expansion, 4426 trigraph conversion, escaped newline splicing, and processing of 4427 most directives. The preprocessor still recognizes and removes 4428 comments, so that you can pass a file preprocessed with `-C' to 4429 the compiler without problems. In this mode the integrated 4430 preprocessor is little more than a tokenizer for the front ends. 4431 4432 `-fpreprocessed' is implicit if the input file has one of the 4433 extensions `.i', `.ii' or `.mi'. These are the extensions that 4434 GCC uses for preprocessed files created by `-save-temps'. 4435 4436`-ftabstop=WIDTH' 4437 Set the distance between tab stops. This helps the preprocessor 4438 report correct column numbers in warnings or errors, even if tabs 4439 appear on the line. If the value is less than 1 or greater than 4440 100, the option is ignored. The default is 8. 4441 4442`-fexec-charset=CHARSET' 4443 Set the execution character set, used for string and character 4444 constants. The default is UTF-8. CHARSET can be any encoding 4445 supported by the system's `iconv' library routine. 4446 4447`-fwide-exec-charset=CHARSET' 4448 Set the wide execution character set, used for wide string and 4449 character constants. The default is UTF-32 or UTF-16, whichever 4450 corresponds to the width of `wchar_t'. As with `-fexec-charset', 4451 CHARSET can be any encoding supported by the system's `iconv' 4452 library routine; however, you will have problems with encodings 4453 that do not fit exactly in `wchar_t'. 4454 4455`-finput-charset=CHARSET' 4456 Set the input character set, used for translation from the 4457 character set of the input file to the source character set used 4458 by GCC. If the locale does not specify, or GCC cannot get this 4459 information from the locale, the default is UTF-8. This can be 4460 overridden by either the locale or this command line option. 4461 Currently the command line option takes precedence if there's a 4462 conflict. CHARSET can be any encoding supported by the system's 4463 `iconv' library routine. 4464 4465`-fworking-directory' 4466 Enable generation of linemarkers in the preprocessor output that 4467 will let the compiler know the current working directory at the 4468 time of preprocessing. When this option is enabled, the 4469 preprocessor will emit, after the initial linemarker, a second 4470 linemarker with the current working directory followed by two 4471 slashes. GCC will use this directory, when it's present in the 4472 preprocessed input, as the directory emitted as the current 4473 working directory in some debugging information formats. This 4474 option is implicitly enabled if debugging information is enabled, 4475 but this can be inhibited with the negated form 4476 `-fno-working-directory'. If the `-P' flag is present in the 4477 command line, this option has no effect, since no `#line' 4478 directives are emitted whatsoever. 4479 4480`-fno-show-column' 4481 Do not print column numbers in diagnostics. This may be necessary 4482 if diagnostics are being scanned by a program that does not 4483 understand the column numbers, such as `dejagnu'. 4484 4485`-A PREDICATE=ANSWER' 4486 Make an assertion with the predicate PREDICATE and answer ANSWER. 4487 This form is preferred to the older form `-A PREDICATE(ANSWER)', 4488 which is still supported, because it does not use shell special 4489 characters. *Note Obsolete Features::. 4490 4491`-A -PREDICATE=ANSWER' 4492 Cancel an assertion with the predicate PREDICATE and answer ANSWER. 4493 4494`-dCHARS' 4495 CHARS is a sequence of one or more of the following characters, 4496 and must not be preceded by a space. Other characters are 4497 interpreted by the compiler proper, or reserved for future 4498 versions of GCC, and so are silently ignored. If you specify 4499 characters whose behavior conflicts, the result is undefined. 4500 4501 `M' 4502 Instead of the normal output, generate a list of `#define' 4503 directives for all the macros defined during the execution of 4504 the preprocessor, including predefined macros. This gives 4505 you a way of finding out what is predefined in your version 4506 of the preprocessor. Assuming you have no file `foo.h', the 4507 command 4508 4509 touch foo.h; cpp -dM foo.h 4510 4511 will show all the predefined macros. 4512 4513 If you use `-dM' without the `-E' option, `-dM' is 4514 interpreted as a synonym for `-fdump-rtl-mach'. *Note 4515 Debugging Options: (gcc)Debugging Options. 4516 4517 `D' 4518 Like `M' except in two respects: it does _not_ include the 4519 predefined macros, and it outputs _both_ the `#define' 4520 directives and the result of preprocessing. Both kinds of 4521 output go to the standard output file. 4522 4523 `N' 4524 Like `D', but emit only the macro names, not their expansions. 4525 4526 `I' 4527 Output `#include' directives in addition to the result of 4528 preprocessing. 4529 4530 `U' 4531 Like `D' except that only macros that are expanded, or whose 4532 definedness is tested in preprocessor directives, are output; 4533 the output is delayed until the use or test of the macro; and 4534 `#undef' directives are also output for macros tested but 4535 undefined at the time. 4536 4537`-P' 4538 Inhibit generation of linemarkers in the output from the 4539 preprocessor. This might be useful when running the preprocessor 4540 on something that is not C code, and will be sent to a program 4541 which might be confused by the linemarkers. *Note Preprocessor 4542 Output::. 4543 4544`-C' 4545 Do not discard comments. All comments are passed through to the 4546 output file, except for comments in processed directives, which 4547 are deleted along with the directive. 4548 4549 You should be prepared for side effects when using `-C'; it causes 4550 the preprocessor to treat comments as tokens in their own right. 4551 For example, comments appearing at the start of what would be a 4552 directive line have the effect of turning that line into an 4553 ordinary source line, since the first token on the line is no 4554 longer a `#'. 4555 4556`-CC' 4557 Do not discard comments, including during macro expansion. This is 4558 like `-C', except that comments contained within macros are also 4559 passed through to the output file where the macro is expanded. 4560 4561 In addition to the side-effects of the `-C' option, the `-CC' 4562 option causes all C++-style comments inside a macro to be 4563 converted to C-style comments. This is to prevent later use of 4564 that macro from inadvertently commenting out the remainder of the 4565 source line. 4566 4567 The `-CC' option is generally used to support lint comments. 4568 4569`-traditional-cpp' 4570 Try to imitate the behavior of old-fashioned C preprocessors, as 4571 opposed to ISO C preprocessors. *Note Traditional Mode::. 4572 4573`-trigraphs' 4574 Process trigraph sequences. *Note Initial processing::. 4575 4576`-remap' 4577 Enable special code to work around file systems which only permit 4578 very short file names, such as MS-DOS. 4579 4580`--help' 4581`--target-help' 4582 Print text describing all the command line options instead of 4583 preprocessing anything. 4584 4585`-v' 4586 Verbose mode. Print out GNU CPP's version number at the beginning 4587 of execution, and report the final form of the include path. 4588 4589`-H' 4590 Print the name of each header file used, in addition to other 4591 normal activities. Each name is indented to show how deep in the 4592 `#include' stack it is. Precompiled header files are also 4593 printed, even if they are found to be invalid; an invalid 4594 precompiled header file is printed with `...x' and a valid one 4595 with `...!' . 4596 4597`-version' 4598`--version' 4599 Print out GNU CPP's version number. With one dash, proceed to 4600 preprocess as normal. With two dashes, exit immediately. 4601 4602 4603File: cpp.info, Node: Environment Variables, Next: GNU Free Documentation License, Prev: Invocation, Up: Top 4604 460513 Environment Variables 4606************************ 4607 4608This section describes the environment variables that affect how CPP 4609operates. You can use them to specify directories or prefixes to use 4610when searching for include files, or to control dependency output. 4611 4612 Note that you can also specify places to search using options such as 4613`-I', and control dependency output with options like `-M' (*note 4614Invocation::). These take precedence over environment variables, which 4615in turn take precedence over the configuration of GCC. 4616 4617`CPATH' 4618`C_INCLUDE_PATH' 4619`CPLUS_INCLUDE_PATH' 4620`OBJC_INCLUDE_PATH' 4621 Each variable's value is a list of directories separated by a 4622 special character, much like `PATH', in which to look for header 4623 files. The special character, `PATH_SEPARATOR', is 4624 target-dependent and determined at GCC build time. For Microsoft 4625 Windows-based targets it is a semicolon, and for almost all other 4626 targets it is a colon. 4627 4628 `CPATH' specifies a list of directories to be searched as if 4629 specified with `-I', but after any paths given with `-I' options 4630 on the command line. This environment variable is used regardless 4631 of which language is being preprocessed. 4632 4633 The remaining environment variables apply only when preprocessing 4634 the particular language indicated. Each specifies a list of 4635 directories to be searched as if specified with `-isystem', but 4636 after any paths given with `-isystem' options on the command line. 4637 4638 In all these variables, an empty element instructs the compiler to 4639 search its current working directory. Empty elements can appear 4640 at the beginning or end of a path. For instance, if the value of 4641 `CPATH' is `:/special/include', that has the same effect as 4642 `-I. -I/special/include'. 4643 4644 See also *Note Search Path::. 4645 4646`DEPENDENCIES_OUTPUT' 4647 If this variable is set, its value specifies how to output 4648 dependencies for Make based on the non-system header files 4649 processed by the compiler. System header files are ignored in the 4650 dependency output. 4651 4652 The value of `DEPENDENCIES_OUTPUT' can be just a file name, in 4653 which case the Make rules are written to that file, guessing the 4654 target name from the source file name. Or the value can have the 4655 form `FILE TARGET', in which case the rules are written to file 4656 FILE using TARGET as the target name. 4657 4658 In other words, this environment variable is equivalent to 4659 combining the options `-MM' and `-MF' (*note Invocation::), with 4660 an optional `-MT' switch too. 4661 4662`SUNPRO_DEPENDENCIES' 4663 This variable is the same as `DEPENDENCIES_OUTPUT' (see above), 4664 except that system header files are not ignored, so it implies 4665 `-M' rather than `-MM'. However, the dependence on the main input 4666 file is omitted. *Note Invocation::. 4667 4668 4669File: cpp.info, Node: GNU Free Documentation License, Next: Index of Directives, Prev: Environment Variables, Up: Top 4670 4671GNU Free Documentation License 4672****************************** 4673 4674 Version 1.2, November 2002 4675 4676 Copyright (C) 2000,2001,2002 Free Software Foundation, Inc. 4677 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 4678 4679 Everyone is permitted to copy and distribute verbatim copies 4680 of this license document, but changing it is not allowed. 4681 4682 0. PREAMBLE 4683 4684 The purpose of this License is to make a manual, textbook, or other 4685 functional and useful document "free" in the sense of freedom: to 4686 assure everyone the effective freedom to copy and redistribute it, 4687 with or without modifying it, either commercially or 4688 noncommercially. Secondarily, this License preserves for the 4689 author and publisher a way to get credit for their work, while not 4690 being considered responsible for modifications made by others. 4691 4692 This License is a kind of "copyleft", which means that derivative 4693 works of the document must themselves be free in the same sense. 4694 It complements the GNU General Public License, which is a copyleft 4695 license designed for free software. 4696 4697 We have designed this License in order to use it for manuals for 4698 free software, because free software needs free documentation: a 4699 free program should come with manuals providing the same freedoms 4700 that the software does. But this License is not limited to 4701 software manuals; it can be used for any textual work, regardless 4702 of subject matter or whether it is published as a printed book. 4703 We recommend this License principally for works whose purpose is 4704 instruction or reference. 4705 4706 1. APPLICABILITY AND DEFINITIONS 4707 4708 This License applies to any manual or other work, in any medium, 4709 that contains a notice placed by the copyright holder saying it 4710 can be distributed under the terms of this License. Such a notice 4711 grants a world-wide, royalty-free license, unlimited in duration, 4712 to use that work under the conditions stated herein. The 4713 "Document", below, refers to any such manual or work. Any member 4714 of the public is a licensee, and is addressed as "you". You 4715 accept the license if you copy, modify or distribute the work in a 4716 way requiring permission under copyright law. 4717 4718 A "Modified Version" of the Document means any work containing the 4719 Document or a portion of it, either copied verbatim, or with 4720 modifications and/or translated into another language. 4721 4722 A "Secondary Section" is a named appendix or a front-matter section 4723 of the Document that deals exclusively with the relationship of the 4724 publishers or authors of the Document to the Document's overall 4725 subject (or to related matters) and contains nothing that could 4726 fall directly within that overall subject. (Thus, if the Document 4727 is in part a textbook of mathematics, a Secondary Section may not 4728 explain any mathematics.) The relationship could be a matter of 4729 historical connection with the subject or with related matters, or 4730 of legal, commercial, philosophical, ethical or political position 4731 regarding them. 4732 4733 The "Invariant Sections" are certain Secondary Sections whose 4734 titles are designated, as being those of Invariant Sections, in 4735 the notice that says that the Document is released under this 4736 License. If a section does not fit the above definition of 4737 Secondary then it is not allowed to be designated as Invariant. 4738 The Document may contain zero Invariant Sections. If the Document 4739 does not identify any Invariant Sections then there are none. 4740 4741 The "Cover Texts" are certain short passages of text that are 4742 listed, as Front-Cover Texts or Back-Cover Texts, in the notice 4743 that says that the Document is released under this License. A 4744 Front-Cover Text may be at most 5 words, and a Back-Cover Text may 4745 be at most 25 words. 4746 4747 A "Transparent" copy of the Document means a machine-readable copy, 4748 represented in a format whose specification is available to the 4749 general public, that is suitable for revising the document 4750 straightforwardly with generic text editors or (for images 4751 composed of pixels) generic paint programs or (for drawings) some 4752 widely available drawing editor, and that is suitable for input to 4753 text formatters or for automatic translation to a variety of 4754 formats suitable for input to text formatters. A copy made in an 4755 otherwise Transparent file format whose markup, or absence of 4756 markup, has been arranged to thwart or discourage subsequent 4757 modification by readers is not Transparent. An image format is 4758 not Transparent if used for any substantial amount of text. A 4759 copy that is not "Transparent" is called "Opaque". 4760 4761 Examples of suitable formats for Transparent copies include plain 4762 ASCII without markup, Texinfo input format, LaTeX input format, 4763 SGML or XML using a publicly available DTD, and 4764 standard-conforming simple HTML, PostScript or PDF designed for 4765 human modification. Examples of transparent image formats include 4766 PNG, XCF and JPG. Opaque formats include proprietary formats that 4767 can be read and edited only by proprietary word processors, SGML or 4768 XML for which the DTD and/or processing tools are not generally 4769 available, and the machine-generated HTML, PostScript or PDF 4770 produced by some word processors for output purposes only. 4771 4772 The "Title Page" means, for a printed book, the title page itself, 4773 plus such following pages as are needed to hold, legibly, the 4774 material this License requires to appear in the title page. For 4775 works in formats which do not have any title page as such, "Title 4776 Page" means the text near the most prominent appearance of the 4777 work's title, preceding the beginning of the body of the text. 4778 4779 A section "Entitled XYZ" means a named subunit of the Document 4780 whose title either is precisely XYZ or contains XYZ in parentheses 4781 following text that translates XYZ in another language. (Here XYZ 4782 stands for a specific section name mentioned below, such as 4783 "Acknowledgements", "Dedications", "Endorsements", or "History".) 4784 To "Preserve the Title" of such a section when you modify the 4785 Document means that it remains a section "Entitled XYZ" according 4786 to this definition. 4787 4788 The Document may include Warranty Disclaimers next to the notice 4789 which states that this License applies to the Document. These 4790 Warranty Disclaimers are considered to be included by reference in 4791 this License, but only as regards disclaiming warranties: any other 4792 implication that these Warranty Disclaimers may have is void and 4793 has no effect on the meaning of this License. 4794 4795 2. VERBATIM COPYING 4796 4797 You may copy and distribute the Document in any medium, either 4798 commercially or noncommercially, provided that this License, the 4799 copyright notices, and the license notice saying this License 4800 applies to the Document are reproduced in all copies, and that you 4801 add no other conditions whatsoever to those of this License. You 4802 may not use technical measures to obstruct or control the reading 4803 or further copying of the copies you make or distribute. However, 4804 you may accept compensation in exchange for copies. If you 4805 distribute a large enough number of copies you must also follow 4806 the conditions in section 3. 4807 4808 You may also lend copies, under the same conditions stated above, 4809 and you may publicly display copies. 4810 4811 3. COPYING IN QUANTITY 4812 4813 If you publish printed copies (or copies in media that commonly 4814 have printed covers) of the Document, numbering more than 100, and 4815 the Document's license notice requires Cover Texts, you must 4816 enclose the copies in covers that carry, clearly and legibly, all 4817 these Cover Texts: Front-Cover Texts on the front cover, and 4818 Back-Cover Texts on the back cover. Both covers must also clearly 4819 and legibly identify you as the publisher of these copies. The 4820 front cover must present the full title with all words of the 4821 title equally prominent and visible. You may add other material 4822 on the covers in addition. Copying with changes limited to the 4823 covers, as long as they preserve the title of the Document and 4824 satisfy these conditions, can be treated as verbatim copying in 4825 other respects. 4826 4827 If the required texts for either cover are too voluminous to fit 4828 legibly, you should put the first ones listed (as many as fit 4829 reasonably) on the actual cover, and continue the rest onto 4830 adjacent pages. 4831 4832 If you publish or distribute Opaque copies of the Document 4833 numbering more than 100, you must either include a 4834 machine-readable Transparent copy along with each Opaque copy, or 4835 state in or with each Opaque copy a computer-network location from 4836 which the general network-using public has access to download 4837 using public-standard network protocols a complete Transparent 4838 copy of the Document, free of added material. If you use the 4839 latter option, you must take reasonably prudent steps, when you 4840 begin distribution of Opaque copies in quantity, to ensure that 4841 this Transparent copy will remain thus accessible at the stated 4842 location until at least one year after the last time you 4843 distribute an Opaque copy (directly or through your agents or 4844 retailers) of that edition to the public. 4845 4846 It is requested, but not required, that you contact the authors of 4847 the Document well before redistributing any large number of 4848 copies, to give them a chance to provide you with an updated 4849 version of the Document. 4850 4851 4. MODIFICATIONS 4852 4853 You may copy and distribute a Modified Version of the Document 4854 under the conditions of sections 2 and 3 above, provided that you 4855 release the Modified Version under precisely this License, with 4856 the Modified Version filling the role of the Document, thus 4857 licensing distribution and modification of the Modified Version to 4858 whoever possesses a copy of it. In addition, you must do these 4859 things in the Modified Version: 4860 4861 A. Use in the Title Page (and on the covers, if any) a title 4862 distinct from that of the Document, and from those of 4863 previous versions (which should, if there were any, be listed 4864 in the History section of the Document). You may use the 4865 same title as a previous version if the original publisher of 4866 that version gives permission. 4867 4868 B. List on the Title Page, as authors, one or more persons or 4869 entities responsible for authorship of the modifications in 4870 the Modified Version, together with at least five of the 4871 principal authors of the Document (all of its principal 4872 authors, if it has fewer than five), unless they release you 4873 from this requirement. 4874 4875 C. State on the Title page the name of the publisher of the 4876 Modified Version, as the publisher. 4877 4878 D. Preserve all the copyright notices of the Document. 4879 4880 E. Add an appropriate copyright notice for your modifications 4881 adjacent to the other copyright notices. 4882 4883 F. Include, immediately after the copyright notices, a license 4884 notice giving the public permission to use the Modified 4885 Version under the terms of this License, in the form shown in 4886 the Addendum below. 4887 4888 G. Preserve in that license notice the full lists of Invariant 4889 Sections and required Cover Texts given in the Document's 4890 license notice. 4891 4892 H. Include an unaltered copy of this License. 4893 4894 I. Preserve the section Entitled "History", Preserve its Title, 4895 and add to it an item stating at least the title, year, new 4896 authors, and publisher of the Modified Version as given on 4897 the Title Page. If there is no section Entitled "History" in 4898 the Document, create one stating the title, year, authors, 4899 and publisher of the Document as given on its Title Page, 4900 then add an item describing the Modified Version as stated in 4901 the previous sentence. 4902 4903 J. Preserve the network location, if any, given in the Document 4904 for public access to a Transparent copy of the Document, and 4905 likewise the network locations given in the Document for 4906 previous versions it was based on. These may be placed in 4907 the "History" section. You may omit a network location for a 4908 work that was published at least four years before the 4909 Document itself, or if the original publisher of the version 4910 it refers to gives permission. 4911 4912 K. For any section Entitled "Acknowledgements" or "Dedications", 4913 Preserve the Title of the section, and preserve in the 4914 section all the substance and tone of each of the contributor 4915 acknowledgements and/or dedications given therein. 4916 4917 L. Preserve all the Invariant Sections of the Document, 4918 unaltered in their text and in their titles. Section numbers 4919 or the equivalent are not considered part of the section 4920 titles. 4921 4922 M. Delete any section Entitled "Endorsements". Such a section 4923 may not be included in the Modified Version. 4924 4925 N. Do not retitle any existing section to be Entitled 4926 "Endorsements" or to conflict in title with any Invariant 4927 Section. 4928 4929 O. Preserve any Warranty Disclaimers. 4930 4931 If the Modified Version includes new front-matter sections or 4932 appendices that qualify as Secondary Sections and contain no 4933 material copied from the Document, you may at your option 4934 designate some or all of these sections as invariant. To do this, 4935 add their titles to the list of Invariant Sections in the Modified 4936 Version's license notice. These titles must be distinct from any 4937 other section titles. 4938 4939 You may add a section Entitled "Endorsements", provided it contains 4940 nothing but endorsements of your Modified Version by various 4941 parties--for example, statements of peer review or that the text 4942 has been approved by an organization as the authoritative 4943 definition of a standard. 4944 4945 You may add a passage of up to five words as a Front-Cover Text, 4946 and a passage of up to 25 words as a Back-Cover Text, to the end 4947 of the list of Cover Texts in the Modified Version. Only one 4948 passage of Front-Cover Text and one of Back-Cover Text may be 4949 added by (or through arrangements made by) any one entity. If the 4950 Document already includes a cover text for the same cover, 4951 previously added by you or by arrangement made by the same entity 4952 you are acting on behalf of, you may not add another; but you may 4953 replace the old one, on explicit permission from the previous 4954 publisher that added the old one. 4955 4956 The author(s) and publisher(s) of the Document do not by this 4957 License give permission to use their names for publicity for or to 4958 assert or imply endorsement of any Modified Version. 4959 4960 5. COMBINING DOCUMENTS 4961 4962 You may combine the Document with other documents released under 4963 this License, under the terms defined in section 4 above for 4964 modified versions, provided that you include in the combination 4965 all of the Invariant Sections of all of the original documents, 4966 unmodified, and list them all as Invariant Sections of your 4967 combined work in its license notice, and that you preserve all 4968 their Warranty Disclaimers. 4969 4970 The combined work need only contain one copy of this License, and 4971 multiple identical Invariant Sections may be replaced with a single 4972 copy. If there are multiple Invariant Sections with the same name 4973 but different contents, make the title of each such section unique 4974 by adding at the end of it, in parentheses, the name of the 4975 original author or publisher of that section if known, or else a 4976 unique number. Make the same adjustment to the section titles in 4977 the list of Invariant Sections in the license notice of the 4978 combined work. 4979 4980 In the combination, you must combine any sections Entitled 4981 "History" in the various original documents, forming one section 4982 Entitled "History"; likewise combine any sections Entitled 4983 "Acknowledgements", and any sections Entitled "Dedications". You 4984 must delete all sections Entitled "Endorsements." 4985 4986 6. COLLECTIONS OF DOCUMENTS 4987 4988 You may make a collection consisting of the Document and other 4989 documents released under this License, and replace the individual 4990 copies of this License in the various documents with a single copy 4991 that is included in the collection, provided that you follow the 4992 rules of this License for verbatim copying of each of the 4993 documents in all other respects. 4994 4995 You may extract a single document from such a collection, and 4996 distribute it individually under this License, provided you insert 4997 a copy of this License into the extracted document, and follow 4998 this License in all other respects regarding verbatim copying of 4999 that document. 5000 5001 7. AGGREGATION WITH INDEPENDENT WORKS 5002 5003 A compilation of the Document or its derivatives with other 5004 separate and independent documents or works, in or on a volume of 5005 a storage or distribution medium, is called an "aggregate" if the 5006 copyright resulting from the compilation is not used to limit the 5007 legal rights of the compilation's users beyond what the individual 5008 works permit. When the Document is included in an aggregate, this 5009 License does not apply to the other works in the aggregate which 5010 are not themselves derivative works of the Document. 5011 5012 If the Cover Text requirement of section 3 is applicable to these 5013 copies of the Document, then if the Document is less than one half 5014 of the entire aggregate, the Document's Cover Texts may be placed 5015 on covers that bracket the Document within the aggregate, or the 5016 electronic equivalent of covers if the Document is in electronic 5017 form. Otherwise they must appear on printed covers that bracket 5018 the whole aggregate. 5019 5020 8. TRANSLATION 5021 5022 Translation is considered a kind of modification, so you may 5023 distribute translations of the Document under the terms of section 5024 4. Replacing Invariant Sections with translations requires special 5025 permission from their copyright holders, but you may include 5026 translations of some or all Invariant Sections in addition to the 5027 original versions of these Invariant Sections. You may include a 5028 translation of this License, and all the license notices in the 5029 Document, and any Warranty Disclaimers, provided that you also 5030 include the original English version of this License and the 5031 original versions of those notices and disclaimers. In case of a 5032 disagreement between the translation and the original version of 5033 this License or a notice or disclaimer, the original version will 5034 prevail. 5035 5036 If a section in the Document is Entitled "Acknowledgements", 5037 "Dedications", or "History", the requirement (section 4) to 5038 Preserve its Title (section 1) will typically require changing the 5039 actual title. 5040 5041 9. TERMINATION 5042 5043 You may not copy, modify, sublicense, or distribute the Document 5044 except as expressly provided for under this License. Any other 5045 attempt to copy, modify, sublicense or distribute the Document is 5046 void, and will automatically terminate your rights under this 5047 License. However, parties who have received copies, or rights, 5048 from you under this License will not have their licenses 5049 terminated so long as such parties remain in full compliance. 5050 5051 10. FUTURE REVISIONS OF THIS LICENSE 5052 5053 The Free Software Foundation may publish new, revised versions of 5054 the GNU Free Documentation License from time to time. Such new 5055 versions will be similar in spirit to the present version, but may 5056 differ in detail to address new problems or concerns. See 5057 `http://www.gnu.org/copyleft/'. 5058 5059 Each version of the License is given a distinguishing version 5060 number. If the Document specifies that a particular numbered 5061 version of this License "or any later version" applies to it, you 5062 have the option of following the terms and conditions either of 5063 that specified version or of any later version that has been 5064 published (not as a draft) by the Free Software Foundation. If 5065 the Document does not specify a version number of this License, 5066 you may choose any version ever published (not as a draft) by the 5067 Free Software Foundation. 5068 5069ADDENDUM: How to use this License for your documents 5070==================================================== 5071 5072To use this License in a document you have written, include a copy of 5073the License in the document and put the following copyright and license 5074notices just after the title page: 5075 5076 Copyright (C) YEAR YOUR NAME. 5077 Permission is granted to copy, distribute and/or modify this document 5078 under the terms of the GNU Free Documentation License, Version 1.2 5079 or any later version published by the Free Software Foundation; 5080 with no Invariant Sections, no Front-Cover Texts, and no Back-Cover 5081 Texts. A copy of the license is included in the section entitled ``GNU 5082 Free Documentation License''. 5083 5084 If you have Invariant Sections, Front-Cover Texts and Back-Cover 5085Texts, replace the "with...Texts." line with this: 5086 5087 with the Invariant Sections being LIST THEIR TITLES, with 5088 the Front-Cover Texts being LIST, and with the Back-Cover Texts 5089 being LIST. 5090 5091 If you have Invariant Sections without Cover Texts, or some other 5092combination of the three, merge those two alternatives to suit the 5093situation. 5094 5095 If your document contains nontrivial examples of program code, we 5096recommend releasing these examples in parallel under your choice of 5097free software license, such as the GNU General Public License, to 5098permit their use in free software. 5099 5100 5101File: cpp.info, Node: Index of Directives, Next: Option Index, Prev: GNU Free Documentation License, Up: Top 5102 5103Index of Directives 5104******************* 5105 5106[index] 5107* Menu: 5108 5109* #assert: Obsolete Features. (line 48) 5110* #define: Object-like Macros. (line 11) 5111* #elif: Elif. (line 6) 5112* #else: Else. (line 6) 5113* #endif: Ifdef. (line 6) 5114* #error: Diagnostics. (line 6) 5115* #ident: Other Directives. (line 6) 5116* #if: Conditional Syntax. (line 6) 5117* #ifdef: Ifdef. (line 6) 5118* #ifndef: Ifdef. (line 40) 5119* #import: Alternatives to Wrapper #ifndef. 5120 (line 11) 5121* #include: Include Syntax. (line 6) 5122* #include_next: Wrapper Headers. (line 6) 5123* #line: Line Control. (line 20) 5124* #pragma GCC dependency: Pragmas. (line 55) 5125* #pragma GCC poison: Pragmas. (line 67) 5126* #pragma GCC system_header <1>: Pragmas. (line 94) 5127* #pragma GCC system_header: System Headers. (line 31) 5128* #sccs: Other Directives. (line 6) 5129* #unassert: Obsolete Features. (line 59) 5130* #undef: Undefining and Redefining Macros. 5131 (line 6) 5132* #warning: Diagnostics. (line 27) 5133 5134 5135File: cpp.info, Node: Option Index, Next: Concept Index, Prev: Index of Directives, Up: Top 5136 5137Option Index 5138************ 5139 5140CPP's command line options and environment variables are indexed here 5141without any initial `-' or `--'. 5142 5143[index] 5144* Menu: 5145 5146* A: Invocation. (line 524) 5147* ansi: Invocation. (line 308) 5148* C: Invocation. (line 583) 5149* C_INCLUDE_PATH: Environment Variables. 5150 (line 16) 5151* CPATH: Environment Variables. 5152 (line 15) 5153* CPLUS_INCLUDE_PATH: Environment Variables. 5154 (line 17) 5155* D: Invocation. (line 39) 5156* dD: Invocation. (line 556) 5157* DEPENDENCIES_OUTPUT: Environment Variables. 5158 (line 44) 5159* dI: Invocation. (line 565) 5160* dM: Invocation. (line 540) 5161* dN: Invocation. (line 562) 5162* dU: Invocation. (line 569) 5163* fdirectives-only: Invocation. (line 432) 5164* fdollars-in-identifiers: Invocation. (line 454) 5165* fexec-charset: Invocation. (line 481) 5166* fextended-identifiers: Invocation. (line 457) 5167* finput-charset: Invocation. (line 494) 5168* fno-show-column: Invocation. (line 519) 5169* fno-working-directory: Invocation. (line 504) 5170* fpreprocessed: Invocation. (line 462) 5171* ftabstop: Invocation. (line 475) 5172* fwide-exec-charset: Invocation. (line 486) 5173* fworking-directory: Invocation. (line 504) 5174* H: Invocation. (line 628) 5175* help: Invocation. (line 620) 5176* I: Invocation. (line 71) 5177* I-: Invocation. (line 347) 5178* idirafter: Invocation. (line 389) 5179* imacros: Invocation. (line 380) 5180* imultilib: Invocation. (line 412) 5181* include: Invocation. (line 369) 5182* iprefix: Invocation. (line 396) 5183* iquote: Invocation. (line 424) 5184* isysroot: Invocation. (line 408) 5185* isystem: Invocation. (line 416) 5186* iwithprefix: Invocation. (line 402) 5187* iwithprefixbefore: Invocation. (line 402) 5188* M: Invocation. (line 180) 5189* MD: Invocation. (line 269) 5190* MF: Invocation. (line 215) 5191* MG: Invocation. (line 224) 5192* MM: Invocation. (line 205) 5193* MMD: Invocation. (line 285) 5194* MP: Invocation. (line 234) 5195* MQ: Invocation. (line 260) 5196* MT: Invocation. (line 246) 5197* nostdinc: Invocation. (line 359) 5198* nostdinc++: Invocation. (line 364) 5199* o: Invocation. (line 82) 5200* OBJC_INCLUDE_PATH: Environment Variables. 5201 (line 18) 5202* P: Invocation. (line 576) 5203* pedantic: Invocation. (line 170) 5204* pedantic-errors: Invocation. (line 175) 5205* remap: Invocation. (line 615) 5206* std=: Invocation. (line 308) 5207* SUNPRO_DEPENDENCIES: Environment Variables. 5208 (line 60) 5209* target-help: Invocation. (line 620) 5210* traditional-cpp: Invocation. (line 608) 5211* trigraphs: Invocation. (line 612) 5212* U: Invocation. (line 62) 5213* undef: Invocation. (line 66) 5214* v: Invocation. (line 624) 5215* version: Invocation. (line 637) 5216* w: Invocation. (line 166) 5217* Wall: Invocation. (line 88) 5218* Wcomment: Invocation. (line 96) 5219* Wcomments: Invocation. (line 96) 5220* Wendif-labels: Invocation. (line 143) 5221* Werror: Invocation. (line 156) 5222* Wsystem-headers: Invocation. (line 160) 5223* Wtraditional: Invocation. (line 113) 5224* Wtrigraphs: Invocation. (line 101) 5225* Wundef: Invocation. (line 119) 5226* Wunused-macros: Invocation. (line 124) 5227* x: Invocation. (line 292) 5228 5229 5230File: cpp.info, Node: Concept Index, Prev: Option Index, Up: Top 5231 5232Concept Index 5233************* 5234 5235[index] 5236* Menu: 5237 5238* # operator: Stringification. (line 6) 5239* ## operator: Concatenation. (line 6) 5240* _Pragma: Pragmas. (line 25) 5241* alternative tokens: Tokenization. (line 106) 5242* arguments: Macro Arguments. (line 6) 5243* arguments in macro definitions: Macro Arguments. (line 6) 5244* assertions: Obsolete Features. (line 13) 5245* assertions, canceling: Obsolete Features. (line 59) 5246* backslash-newline: Initial processing. (line 61) 5247* block comments: Initial processing. (line 77) 5248* C++ named operators: C++ Named Operators. (line 6) 5249* character constants: Tokenization. (line 85) 5250* character set, execution: Invocation. (line 481) 5251* character set, input: Invocation. (line 494) 5252* character set, wide execution: Invocation. (line 486) 5253* command line: Invocation. (line 6) 5254* commenting out code: Deleted Code. (line 6) 5255* comments: Initial processing. (line 77) 5256* common predefined macros: Common Predefined Macros. 5257 (line 6) 5258* computed includes: Computed Includes. (line 6) 5259* concatenation: Concatenation. (line 6) 5260* conditional group: Ifdef. (line 14) 5261* conditionals: Conditionals. (line 6) 5262* continued lines: Initial processing. (line 61) 5263* controlling macro: Once-Only Headers. (line 35) 5264* defined: Defined. (line 6) 5265* dependencies for make as output: Environment Variables. 5266 (line 45) 5267* dependencies, make: Invocation. (line 180) 5268* diagnostic: Diagnostics. (line 6) 5269* differences from previous versions: Differences from previous versions. 5270 (line 6) 5271* digraphs: Tokenization. (line 106) 5272* directive line: The preprocessing language. 5273 (line 6) 5274* directive name: The preprocessing language. 5275 (line 6) 5276* directives: The preprocessing language. 5277 (line 6) 5278* empty macro arguments: Macro Arguments. (line 66) 5279* environment variables: Environment Variables. 5280 (line 6) 5281* expansion of arguments: Argument Prescan. (line 6) 5282* FDL, GNU Free Documentation License: GNU Free Documentation License. 5283 (line 6) 5284* function-like macros: Function-like Macros. 5285 (line 6) 5286* grouping options: Invocation. (line 34) 5287* guard macro: Once-Only Headers. (line 35) 5288* header file: Header Files. (line 6) 5289* header file names: Tokenization. (line 85) 5290* identifiers: Tokenization. (line 34) 5291* implementation limits: Implementation limits. 5292 (line 6) 5293* implementation-defined behavior: Implementation-defined behavior. 5294 (line 6) 5295* including just once: Once-Only Headers. (line 6) 5296* invocation: Invocation. (line 6) 5297* iso646.h: C++ Named Operators. (line 6) 5298* line comments: Initial processing. (line 77) 5299* line control: Line Control. (line 6) 5300* line endings: Initial processing. (line 14) 5301* linemarkers: Preprocessor Output. (line 28) 5302* macro argument expansion: Argument Prescan. (line 6) 5303* macro arguments and directives: Directives Within Macro Arguments. 5304 (line 6) 5305* macros in include: Computed Includes. (line 6) 5306* macros with arguments: Macro Arguments. (line 6) 5307* macros with variable arguments: Variadic Macros. (line 6) 5308* make: Invocation. (line 180) 5309* manifest constants: Object-like Macros. (line 6) 5310* named operators: C++ Named Operators. (line 6) 5311* newlines in macro arguments: Newlines in Arguments. 5312 (line 6) 5313* null directive: Other Directives. (line 15) 5314* numbers: Tokenization. (line 61) 5315* object-like macro: Object-like Macros. (line 6) 5316* options: Invocation. (line 38) 5317* options, grouping: Invocation. (line 34) 5318* other tokens: Tokenization. (line 120) 5319* output format: Preprocessor Output. (line 12) 5320* overriding a header file: Wrapper Headers. (line 6) 5321* parentheses in macro bodies: Operator Precedence Problems. 5322 (line 6) 5323* pitfalls of macros: Macro Pitfalls. (line 6) 5324* predefined macros: Predefined Macros. (line 6) 5325* predefined macros, system-specific: System-specific Predefined Macros. 5326 (line 6) 5327* predicates: Obsolete Features. (line 26) 5328* preprocessing directives: The preprocessing language. 5329 (line 6) 5330* preprocessing numbers: Tokenization. (line 61) 5331* preprocessing tokens: Tokenization. (line 6) 5332* prescan of macro arguments: Argument Prescan. (line 6) 5333* problems with macros: Macro Pitfalls. (line 6) 5334* punctuators: Tokenization. (line 106) 5335* redefining macros: Undefining and Redefining Macros. 5336 (line 6) 5337* repeated inclusion: Once-Only Headers. (line 6) 5338* reporting errors: Diagnostics. (line 6) 5339* reporting warnings: Diagnostics. (line 6) 5340* reserved namespace: System-specific Predefined Macros. 5341 (line 6) 5342* self-reference: Self-Referential Macros. 5343 (line 6) 5344* semicolons (after macro calls): Swallowing the Semicolon. 5345 (line 6) 5346* side effects (in macro arguments): Duplication of Side Effects. 5347 (line 6) 5348* standard predefined macros.: Standard Predefined Macros. 5349 (line 6) 5350* string constants: Tokenization. (line 85) 5351* string literals: Tokenization. (line 85) 5352* stringification: Stringification. (line 6) 5353* symbolic constants: Object-like Macros. (line 6) 5354* system header files <1>: System Headers. (line 6) 5355* system header files: Header Files. (line 13) 5356* system-specific predefined macros: System-specific Predefined Macros. 5357 (line 6) 5358* testing predicates: Obsolete Features. (line 37) 5359* token concatenation: Concatenation. (line 6) 5360* token pasting: Concatenation. (line 6) 5361* tokens: Tokenization. (line 6) 5362* trigraphs: Initial processing. (line 32) 5363* undefining macros: Undefining and Redefining Macros. 5364 (line 6) 5365* unsafe macros: Duplication of Side Effects. 5366 (line 6) 5367* variable number of arguments: Variadic Macros. (line 6) 5368* variadic macros: Variadic Macros. (line 6) 5369* wrapper #ifndef: Once-Only Headers. (line 6) 5370* wrapper headers: Wrapper Headers. (line 6) 5371 5372 5373 5374Tag Table: 5375Node: Top1165 5376Node: Overview3897 5377Node: Character sets6718 5378Ref: Character sets-Footnote-18901 5379Node: Initial processing9082 5380Ref: trigraphs10641 5381Node: Tokenization14843 5382Ref: Tokenization-Footnote-121979 5383Node: The preprocessing language22090 5384Node: Header Files24968 5385Node: Include Syntax26884 5386Node: Include Operation28521 5387Node: Search Path30369 5388Node: Once-Only Headers33559 5389Node: Alternatives to Wrapper #ifndef35218 5390Node: Computed Includes36961 5391Node: Wrapper Headers40119 5392Node: System Headers42545 5393Node: Macros44595 5394Node: Object-like Macros45736 5395Node: Function-like Macros49326 5396Node: Macro Arguments50942 5397Node: Stringification55087 5398Node: Concatenation58293 5399Node: Variadic Macros61401 5400Node: Predefined Macros66188 5401Node: Standard Predefined Macros66776 5402Node: Common Predefined Macros72713 5403Node: System-specific Predefined Macros88660 5404Node: C++ Named Operators90681 5405Node: Undefining and Redefining Macros91645 5406Node: Directives Within Macro Arguments93749 5407Node: Macro Pitfalls95297 5408Node: Misnesting95830 5409Node: Operator Precedence Problems96942 5410Node: Swallowing the Semicolon98808 5411Node: Duplication of Side Effects100831 5412Node: Self-Referential Macros103014 5413Node: Argument Prescan105423 5414Node: Newlines in Arguments109177 5415Node: Conditionals110128 5416Node: Conditional Uses111958 5417Node: Conditional Syntax113316 5418Node: Ifdef113636 5419Node: If116797 5420Node: Defined119101 5421Node: Else120384 5422Node: Elif120954 5423Node: Deleted Code122243 5424Node: Diagnostics123490 5425Node: Line Control125107 5426Node: Pragmas128911 5427Node: Other Directives133228 5428Node: Preprocessor Output134278 5429Node: Traditional Mode137479 5430Node: Traditional lexical analysis138537 5431Node: Traditional macros141040 5432Node: Traditional miscellany144842 5433Node: Traditional warnings145839 5434Node: Implementation Details148036 5435Node: Implementation-defined behavior148657 5436Ref: Identifier characters149409 5437Node: Implementation limits152487 5438Node: Obsolete Features155161 5439Node: Differences from previous versions158049 5440Node: Invocation162257 5441Ref: Wtrigraphs166709 5442Ref: dashMF171484 5443Ref: fdollars-in-identifiers180889 5444Node: Environment Variables189052 5445Node: GNU Free Documentation License192018 5446Node: Index of Directives214451 5447Node: Option Index216385 5448Node: Concept Index222569 5449 5450End Tag Table 5451