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