1This is doc/cpp.info, produced by makeinfo version 4.13 from 2/scratch/astubbs/arm-eabi-lite/src/gcc-4.8-2013.11/gcc/doc/cpp.texi. 3 4Copyright (C) 1987-2013 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-2013 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. A fully conforming 1738 implementation of the 1998 C++ standard will define this macro to 1739 `199711L'. The GNU C++ compiler is not yet fully conforming, so 1740 it uses `1' instead. It is hoped to complete the implementation 1741 of standard C++ in the near future. 1742 1743`__OBJC__' 1744 This macro is defined, with value 1, when the Objective-C compiler 1745 is in use. You can use `__OBJC__' to test whether a header is 1746 compiled by a C compiler or an Objective-C compiler. 1747 1748`__ASSEMBLER__' 1749 This macro is defined with value 1 when preprocessing assembly 1750 language. 1751 1752 1753 1754File: cpp.info, Node: Common Predefined Macros, Next: System-specific Predefined Macros, Prev: Standard Predefined Macros, Up: Predefined Macros 1755 17563.7.2 Common Predefined Macros 1757------------------------------ 1758 1759The common predefined macros are GNU C extensions. They are available 1760with the same meanings regardless of the machine or operating system on 1761which you are using GNU C or GNU Fortran. Their names all start with 1762double underscores. 1763 1764`__COUNTER__' 1765 This macro expands to sequential integral values starting from 0. 1766 In conjunction with the `##' operator, this provides a convenient 1767 means to generate unique identifiers. Care must be taken to 1768 ensure that `__COUNTER__' is not expanded prior to inclusion of 1769 precompiled headers which use it. Otherwise, the precompiled 1770 headers will not be used. 1771 1772`__GFORTRAN__' 1773 The GNU Fortran compiler defines this. 1774 1775`__GNUC__' 1776`__GNUC_MINOR__' 1777`__GNUC_PATCHLEVEL__' 1778 These macros are defined by all GNU compilers that use the C 1779 preprocessor: C, C++, Objective-C and Fortran. Their values are 1780 the major version, minor version, and patch level of the compiler, 1781 as integer constants. For example, GCC 3.2.1 will define 1782 `__GNUC__' to 3, `__GNUC_MINOR__' to 2, and `__GNUC_PATCHLEVEL__' 1783 to 1. These macros are also defined if you invoke the 1784 preprocessor directly. 1785 1786 `__GNUC_PATCHLEVEL__' is new to GCC 3.0; it is also present in the 1787 widely-used development snapshots leading up to 3.0 (which identify 1788 themselves as GCC 2.96 or 2.97, depending on which snapshot you 1789 have). 1790 1791 If all you need to know is whether or not your program is being 1792 compiled by GCC, or a non-GCC compiler that claims to accept the 1793 GNU C dialects, you can simply test `__GNUC__'. If you need to 1794 write code which depends on a specific version, you must be more 1795 careful. Each time the minor version is increased, the patch 1796 level is reset to zero; each time the major version is increased 1797 (which happens rarely), the minor version and patch level are 1798 reset. If you wish to use the predefined macros directly in the 1799 conditional, you will need to write it like this: 1800 1801 /* Test for GCC > 3.2.0 */ 1802 #if __GNUC__ > 3 || \ 1803 (__GNUC__ == 3 && (__GNUC_MINOR__ > 2 || \ 1804 (__GNUC_MINOR__ == 2 && \ 1805 __GNUC_PATCHLEVEL__ > 0)) 1806 1807 Another approach is to use the predefined macros to calculate a 1808 single number, then compare that against a threshold: 1809 1810 #define GCC_VERSION (__GNUC__ * 10000 \ 1811 + __GNUC_MINOR__ * 100 \ 1812 + __GNUC_PATCHLEVEL__) 1813 ... 1814 /* Test for GCC > 3.2.0 */ 1815 #if GCC_VERSION > 30200 1816 1817 Many people find this form easier to understand. 1818 1819`__GNUG__' 1820 The GNU C++ compiler defines this. Testing it is equivalent to 1821 testing `(__GNUC__ && __cplusplus)'. 1822 1823`__STRICT_ANSI__' 1824 GCC defines this macro if and only if the `-ansi' switch, or a 1825 `-std' switch specifying strict conformance to some version of ISO 1826 C or ISO C++, was specified when GCC was invoked. It is defined 1827 to `1'. This macro exists primarily to direct GNU libc's header 1828 files to restrict their definitions to the minimal set found in 1829 the 1989 C standard. 1830 1831`__BASE_FILE__' 1832 This macro expands to the name of the main input file, in the form 1833 of a C string constant. This is the source file that was specified 1834 on the command line of the preprocessor or C compiler. 1835 1836`__INCLUDE_LEVEL__' 1837 This macro expands to a decimal integer constant that represents 1838 the depth of nesting in include files. The value of this macro is 1839 incremented on every `#include' directive and decremented at the 1840 end of every included file. It starts out at 0, its value within 1841 the base file specified on the command line. 1842 1843`__ELF__' 1844 This macro is defined if the target uses the ELF object format. 1845 1846`__VERSION__' 1847 This macro expands to a string constant which describes the 1848 version of the compiler in use. You should not rely on its 1849 contents having any particular form, but it can be counted on to 1850 contain at least the release number. 1851 1852`__OPTIMIZE__' 1853`__OPTIMIZE_SIZE__' 1854`__NO_INLINE__' 1855 These macros describe the compilation mode. `__OPTIMIZE__' is 1856 defined in all optimizing compilations. `__OPTIMIZE_SIZE__' is 1857 defined if the compiler is optimizing for size, not speed. 1858 `__NO_INLINE__' is defined if no functions will be inlined into 1859 their callers (when not optimizing, or when inlining has been 1860 specifically disabled by `-fno-inline'). 1861 1862 These macros cause certain GNU header files to provide optimized 1863 definitions, using macros or inline functions, of system library 1864 functions. You should not use these macros in any way unless you 1865 make sure that programs will execute with the same effect whether 1866 or not they are defined. If they are defined, their value is 1. 1867 1868`__GNUC_GNU_INLINE__' 1869 GCC defines this macro if functions declared `inline' will be 1870 handled in GCC's traditional gnu90 mode. Object files will contain 1871 externally visible definitions of all functions declared `inline' 1872 without `extern' or `static'. They will not contain any 1873 definitions of any functions declared `extern inline'. 1874 1875`__GNUC_STDC_INLINE__' 1876 GCC defines this macro if functions declared `inline' will be 1877 handled according to the ISO C99 standard. Object files will 1878 contain externally visible definitions of all functions declared 1879 `extern inline'. They will not contain definitions of any 1880 functions declared `inline' without `extern'. 1881 1882 If this macro is defined, GCC supports the `gnu_inline' function 1883 attribute as a way to always get the gnu90 behavior. Support for 1884 this and `__GNUC_GNU_INLINE__' was added in GCC 4.1.3. If neither 1885 macro is defined, an older version of GCC is being used: `inline' 1886 functions will be compiled in gnu90 mode, and the `gnu_inline' 1887 function attribute will not be recognized. 1888 1889`__CHAR_UNSIGNED__' 1890 GCC defines this macro if and only if the data type `char' is 1891 unsigned on the target machine. It exists to cause the standard 1892 header file `limits.h' to work correctly. You should not use this 1893 macro yourself; instead, refer to the standard macros defined in 1894 `limits.h'. 1895 1896`__WCHAR_UNSIGNED__' 1897 Like `__CHAR_UNSIGNED__', this macro is defined if and only if the 1898 data type `wchar_t' is unsigned and the front-end is in C++ mode. 1899 1900`__REGISTER_PREFIX__' 1901 This macro expands to a single token (not a string constant) which 1902 is the prefix applied to CPU register names in assembly language 1903 for this target. You can use it to write assembly that is usable 1904 in multiple environments. For example, in the `m68k-aout' 1905 environment it expands to nothing, but in the `m68k-coff' 1906 environment it expands to a single `%'. 1907 1908`__USER_LABEL_PREFIX__' 1909 This macro expands to a single token which is the prefix applied to 1910 user labels (symbols visible to C code) in assembly. For example, 1911 in the `m68k-aout' environment it expands to an `_', but in the 1912 `m68k-coff' environment it expands to nothing. 1913 1914 This macro will have the correct definition even if 1915 `-f(no-)underscores' is in use, but it will not be correct if 1916 target-specific options that adjust this prefix are used (e.g. the 1917 OSF/rose `-mno-underscores' option). 1918 1919`__SIZE_TYPE__' 1920`__PTRDIFF_TYPE__' 1921`__WCHAR_TYPE__' 1922`__WINT_TYPE__' 1923`__INTMAX_TYPE__' 1924`__UINTMAX_TYPE__' 1925`__SIG_ATOMIC_TYPE__' 1926`__INT8_TYPE__' 1927`__INT16_TYPE__' 1928`__INT32_TYPE__' 1929`__INT64_TYPE__' 1930`__UINT8_TYPE__' 1931`__UINT16_TYPE__' 1932`__UINT32_TYPE__' 1933`__UINT64_TYPE__' 1934`__INT_LEAST8_TYPE__' 1935`__INT_LEAST16_TYPE__' 1936`__INT_LEAST32_TYPE__' 1937`__INT_LEAST64_TYPE__' 1938`__UINT_LEAST8_TYPE__' 1939`__UINT_LEAST16_TYPE__' 1940`__UINT_LEAST32_TYPE__' 1941`__UINT_LEAST64_TYPE__' 1942`__INT_FAST8_TYPE__' 1943`__INT_FAST16_TYPE__' 1944`__INT_FAST32_TYPE__' 1945`__INT_FAST64_TYPE__' 1946`__UINT_FAST8_TYPE__' 1947`__UINT_FAST16_TYPE__' 1948`__UINT_FAST32_TYPE__' 1949`__UINT_FAST64_TYPE__' 1950`__INTPTR_TYPE__' 1951`__UINTPTR_TYPE__' 1952 These macros are defined to the correct underlying types for the 1953 `size_t', `ptrdiff_t', `wchar_t', `wint_t', `intmax_t', 1954 `uintmax_t', `sig_atomic_t', `int8_t', `int16_t', `int32_t', 1955 `int64_t', `uint8_t', `uint16_t', `uint32_t', `uint64_t', 1956 `int_least8_t', `int_least16_t', `int_least32_t', `int_least64_t', 1957 `uint_least8_t', `uint_least16_t', `uint_least32_t', 1958 `uint_least64_t', `int_fast8_t', `int_fast16_t', `int_fast32_t', 1959 `int_fast64_t', `uint_fast8_t', `uint_fast16_t', `uint_fast32_t', 1960 `uint_fast64_t', `intptr_t', and `uintptr_t' typedefs, 1961 respectively. They exist to make the standard header files 1962 `stddef.h', `stdint.h', and `wchar.h' work correctly. You should 1963 not use these macros directly; instead, include the appropriate 1964 headers and use the typedefs. Some of these macros may not be 1965 defined on particular systems if GCC does not provide a `stdint.h' 1966 header on those systems. 1967 1968`__CHAR_BIT__' 1969 Defined to the number of bits used in the representation of the 1970 `char' data type. It exists to make the standard header given 1971 numerical limits work correctly. You should not use this macro 1972 directly; instead, include the appropriate headers. 1973 1974`__SCHAR_MAX__' 1975`__WCHAR_MAX__' 1976`__SHRT_MAX__' 1977`__INT_MAX__' 1978`__LONG_MAX__' 1979`__LONG_LONG_MAX__' 1980`__WINT_MAX__' 1981`__SIZE_MAX__' 1982`__PTRDIFF_MAX__' 1983`__INTMAX_MAX__' 1984`__UINTMAX_MAX__' 1985`__SIG_ATOMIC_MAX__' 1986`__INT8_MAX__' 1987`__INT16_MAX__' 1988`__INT32_MAX__' 1989`__INT64_MAX__' 1990`__UINT8_MAX__' 1991`__UINT16_MAX__' 1992`__UINT32_MAX__' 1993`__UINT64_MAX__' 1994`__INT_LEAST8_MAX__' 1995`__INT_LEAST16_MAX__' 1996`__INT_LEAST32_MAX__' 1997`__INT_LEAST64_MAX__' 1998`__UINT_LEAST8_MAX__' 1999`__UINT_LEAST16_MAX__' 2000`__UINT_LEAST32_MAX__' 2001`__UINT_LEAST64_MAX__' 2002`__INT_FAST8_MAX__' 2003`__INT_FAST16_MAX__' 2004`__INT_FAST32_MAX__' 2005`__INT_FAST64_MAX__' 2006`__UINT_FAST8_MAX__' 2007`__UINT_FAST16_MAX__' 2008`__UINT_FAST32_MAX__' 2009`__UINT_FAST64_MAX__' 2010`__INTPTR_MAX__' 2011`__UINTPTR_MAX__' 2012`__WCHAR_MIN__' 2013`__WINT_MIN__' 2014`__SIG_ATOMIC_MIN__' 2015 Defined to the maximum value of the `signed char', `wchar_t', 2016 `signed short', `signed int', `signed long', `signed long long', 2017 `wint_t', `size_t', `ptrdiff_t', `intmax_t', `uintmax_t', 2018 `sig_atomic_t', `int8_t', `int16_t', `int32_t', `int64_t', 2019 `uint8_t', `uint16_t', `uint32_t', `uint64_t', `int_least8_t', 2020 `int_least16_t', `int_least32_t', `int_least64_t', 2021 `uint_least8_t', `uint_least16_t', `uint_least32_t', 2022 `uint_least64_t', `int_fast8_t', `int_fast16_t', `int_fast32_t', 2023 `int_fast64_t', `uint_fast8_t', `uint_fast16_t', `uint_fast32_t', 2024 `uint_fast64_t', `intptr_t', and `uintptr_t' types and to the 2025 minimum value of the `wchar_t', `wint_t', and `sig_atomic_t' types 2026 respectively. They exist to make the standard header given 2027 numerical limits work correctly. You should not use these macros 2028 directly; instead, include the appropriate headers. Some of these 2029 macros may not be defined on particular systems if GCC does not 2030 provide a `stdint.h' header on those systems. 2031 2032`__INT8_C' 2033`__INT16_C' 2034`__INT32_C' 2035`__INT64_C' 2036`__UINT8_C' 2037`__UINT16_C' 2038`__UINT32_C' 2039`__UINT64_C' 2040`__INTMAX_C' 2041`__UINTMAX_C' 2042 Defined to implementations of the standard `stdint.h' macros with 2043 the same names without the leading `__'. They exist the make the 2044 implementation of that header work correctly. You should not use 2045 these macros directly; instead, include the appropriate headers. 2046 Some of these macros may not be defined on particular systems if 2047 GCC does not provide a `stdint.h' header on those systems. 2048 2049`__SIZEOF_INT__' 2050`__SIZEOF_LONG__' 2051`__SIZEOF_LONG_LONG__' 2052`__SIZEOF_SHORT__' 2053`__SIZEOF_POINTER__' 2054`__SIZEOF_FLOAT__' 2055`__SIZEOF_DOUBLE__' 2056`__SIZEOF_LONG_DOUBLE__' 2057`__SIZEOF_SIZE_T__' 2058`__SIZEOF_WCHAR_T__' 2059`__SIZEOF_WINT_T__' 2060`__SIZEOF_PTRDIFF_T__' 2061 Defined to the number of bytes of the C standard data types: `int', 2062 `long', `long long', `short', `void *', `float', `double', `long 2063 double', `size_t', `wchar_t', `wint_t' and `ptrdiff_t'. 2064 2065`__BYTE_ORDER__' 2066`__ORDER_LITTLE_ENDIAN__' 2067`__ORDER_BIG_ENDIAN__' 2068`__ORDER_PDP_ENDIAN__' 2069 `__BYTE_ORDER__' is defined to one of the values 2070 `__ORDER_LITTLE_ENDIAN__', `__ORDER_BIG_ENDIAN__', or 2071 `__ORDER_PDP_ENDIAN__' to reflect the layout of multi-byte and 2072 multi-word quantities in memory. If `__BYTE_ORDER__' is equal to 2073 `__ORDER_LITTLE_ENDIAN__' or `__ORDER_BIG_ENDIAN__', then 2074 multi-byte and multi-word quantities are laid out identically: the 2075 byte (word) at the lowest address is the least significant or most 2076 significant byte (word) of the quantity, respectively. If 2077 `__BYTE_ORDER__' is equal to `__ORDER_PDP_ENDIAN__', then bytes in 2078 16-bit words are laid out in a little-endian fashion, whereas the 2079 16-bit subwords of a 32-bit quantity are laid out in big-endian 2080 fashion. 2081 2082 You should use these macros for testing like this: 2083 2084 /* Test for a little-endian machine */ 2085 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 2086 2087`__FLOAT_WORD_ORDER__' 2088 `__FLOAT_WORD_ORDER__' is defined to one of the values 2089 `__ORDER_LITTLE_ENDIAN__' or `__ORDER_BIG_ENDIAN__' to reflect the 2090 layout of the words of multi-word floating-point quantities. 2091 2092`__DEPRECATED' 2093 This macro is defined, with value 1, when compiling a C++ source 2094 file with warnings about deprecated constructs enabled. These 2095 warnings are enabled by default, but can be disabled with 2096 `-Wno-deprecated'. 2097 2098`__EXCEPTIONS' 2099 This macro is defined, with value 1, when compiling a C++ source 2100 file with exceptions enabled. If `-fno-exceptions' is used when 2101 compiling the file, then this macro is not defined. 2102 2103`__GXX_RTTI' 2104 This macro is defined, with value 1, when compiling a C++ source 2105 file with runtime type identification enabled. If `-fno-rtti' is 2106 used when compiling the file, then this macro is not defined. 2107 2108`__USING_SJLJ_EXCEPTIONS__' 2109 This macro is defined, with value 1, if the compiler uses the old 2110 mechanism based on `setjmp' and `longjmp' for exception handling. 2111 2112`__GXX_EXPERIMENTAL_CXX0X__' 2113 This macro is defined when compiling a C++ source file with the 2114 option `-std=c++0x' or `-std=gnu++0x'. It indicates that some 2115 features likely to be included in C++0x are available. Note that 2116 these features are experimental, and may change or be removed in 2117 future versions of GCC. 2118 2119`__GXX_WEAK__' 2120 This macro is defined when compiling a C++ source file. It has the 2121 value 1 if the compiler will use weak symbols, COMDAT sections, or 2122 other similar techniques to collapse symbols with "vague linkage" 2123 that are defined in multiple translation units. If the compiler 2124 will not collapse such symbols, this macro is defined with value 2125 0. In general, user code should not need to make use of this 2126 macro; the purpose of this macro is to ease implementation of the 2127 C++ runtime library provided with G++. 2128 2129`__NEXT_RUNTIME__' 2130 This macro is defined, with value 1, if (and only if) the NeXT 2131 runtime (as in `-fnext-runtime') is in use for Objective-C. If 2132 the GNU runtime is used, this macro is not defined, so that you 2133 can use this macro to determine which runtime (NeXT or GNU) is 2134 being used. 2135 2136`__LP64__' 2137`_LP64' 2138 These macros are defined, with value 1, if (and only if) the 2139 compilation is for a target where `long int' and pointer both use 2140 64-bits and `int' uses 32-bit. 2141 2142`__SSP__' 2143 This macro is defined, with value 1, when `-fstack-protector' is in 2144 use. 2145 2146`__SSP_ALL__' 2147 This macro is defined, with value 2, when `-fstack-protector-all' 2148 is in use. 2149 2150`__SANITIZE_ADDRESS__' 2151 This macro is defined, with value 1, when `-fsanitize=address' is 2152 in use. 2153 2154`__TIMESTAMP__' 2155 This macro expands to a string constant that describes the date 2156 and time of the last modification of the current source file. The 2157 string constant contains abbreviated day of the week, month, day 2158 of the month, time in hh:mm:ss form, year and looks like 2159 `"Sun Sep 16 01:03:52 1973"'. If the day of the month is less 2160 than 10, it is padded with a space on the left. 2161 2162 If GCC cannot determine the current date, it will emit a warning 2163 message (once per compilation) and `__TIMESTAMP__' will expand to 2164 `"??? ??? ?? ??:??:?? ????"'. 2165 2166`__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1' 2167`__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2' 2168`__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4' 2169`__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8' 2170`__GCC_HAVE_SYNC_COMPARE_AND_SWAP_16' 2171 These macros are defined when the target processor supports atomic 2172 compare and swap operations on operands 1, 2, 4, 8 or 16 bytes in 2173 length, respectively. 2174 2175`__GCC_HAVE_DWARF2_CFI_ASM' 2176 This macro is defined when the compiler is emitting Dwarf2 CFI 2177 directives to the assembler. When this is defined, it is possible 2178 to emit those same directives in inline assembly. 2179 2180`__FP_FAST_FMA' 2181`__FP_FAST_FMAF' 2182`__FP_FAST_FMAL' 2183 These macros are defined with value 1 if the backend supports the 2184 `fma', `fmaf', and `fmal' builtin functions, so that the include 2185 file `math.h' can define the macros `FP_FAST_FMA', `FP_FAST_FMAF', 2186 and `FP_FAST_FMAL' for compatibility with the 1999 C standard. 2187 2188 2189File: cpp.info, Node: System-specific Predefined Macros, Next: C++ Named Operators, Prev: Common Predefined Macros, Up: Predefined Macros 2190 21913.7.3 System-specific Predefined Macros 2192--------------------------------------- 2193 2194The C preprocessor normally predefines several macros that indicate what 2195type of system and machine is in use. They are obviously different on 2196each target supported by GCC. This manual, being for all systems and 2197machines, cannot tell you what their names are, but you can use `cpp 2198-dM' to see them all. *Note Invocation::. All system-specific 2199predefined macros expand to a constant value, so you can test them with 2200either `#ifdef' or `#if'. 2201 2202 The C standard requires that all system-specific macros be part of 2203the "reserved namespace". All names which begin with two underscores, 2204or an underscore and a capital letter, are reserved for the compiler and 2205library to use as they wish. However, historically system-specific 2206macros have had names with no special prefix; for instance, it is common 2207to find `unix' defined on Unix systems. For all such macros, GCC 2208provides a parallel macro with two underscores added at the beginning 2209and the end. If `unix' is defined, `__unix__' will be defined too. 2210There will never be more than two underscores; the parallel of `_mips' 2211is `__mips__'. 2212 2213 When the `-ansi' option, or any `-std' option that requests strict 2214conformance, is given to the compiler, all the system-specific 2215predefined macros outside the reserved namespace are suppressed. The 2216parallel macros, inside the reserved namespace, remain defined. 2217 2218 We are slowly phasing out all predefined macros which are outside the 2219reserved namespace. You should never use them in new programs, and we 2220encourage you to correct older code to use the parallel macros whenever 2221you find it. We don't recommend you use the system-specific macros that 2222are in the reserved namespace, either. It is better in the long run to 2223check specifically for features you need, using a tool such as 2224`autoconf'. 2225 2226 2227File: cpp.info, Node: C++ Named Operators, Prev: System-specific Predefined Macros, Up: Predefined Macros 2228 22293.7.4 C++ Named Operators 2230------------------------- 2231 2232In C++, there are eleven keywords which are simply alternate spellings 2233of operators normally written with punctuation. These keywords are 2234treated as such even in the preprocessor. They function as operators in 2235`#if', and they cannot be defined as macros or poisoned. In C, you can 2236request that those keywords take their C++ meaning by including 2237`iso646.h'. That header defines each one as a normal object-like macro 2238expanding to the appropriate punctuator. 2239 2240 These are the named operators and their corresponding punctuators: 2241 2242Named Operator Punctuator 2243`and' `&&' 2244`and_eq' `&=' 2245`bitand' `&' 2246`bitor' `|' 2247`compl' `~' 2248`not' `!' 2249`not_eq' `!=' 2250`or' `||' 2251`or_eq' `|=' 2252`xor' `^' 2253`xor_eq' `^=' 2254 2255 2256File: cpp.info, Node: Undefining and Redefining Macros, Next: Directives Within Macro Arguments, Prev: Predefined Macros, Up: Macros 2257 22583.8 Undefining and Redefining Macros 2259==================================== 2260 2261If a macro ceases to be useful, it may be "undefined" with the `#undef' 2262directive. `#undef' takes a single argument, the name of the macro to 2263undefine. You use the bare macro name, even if the macro is 2264function-like. It is an error if anything appears on the line after 2265the macro name. `#undef' has no effect if the name is not a macro. 2266 2267 #define FOO 4 2268 x = FOO; ==> x = 4; 2269 #undef FOO 2270 x = FOO; ==> x = FOO; 2271 2272 Once a macro has been undefined, that identifier may be "redefined" 2273as a macro by a subsequent `#define' directive. The new definition 2274need not have any resemblance to the old definition. 2275 2276 However, if an identifier which is currently a macro is redefined, 2277then the new definition must be "effectively the same" as the old one. 2278Two macro definitions are effectively the same if: 2279 * Both are the same type of macro (object- or function-like). 2280 2281 * All the tokens of the replacement list are the same. 2282 2283 * If there are any parameters, they are the same. 2284 2285 * Whitespace appears in the same places in both. It need not be 2286 exactly the same amount of whitespace, though. Remember that 2287 comments count as whitespace. 2288 2289These definitions are effectively the same: 2290 #define FOUR (2 + 2) 2291 #define FOUR (2 + 2) 2292 #define FOUR (2 /* two */ + 2) 2293 but these are not: 2294 #define FOUR (2 + 2) 2295 #define FOUR ( 2+2 ) 2296 #define FOUR (2 * 2) 2297 #define FOUR(score,and,seven,years,ago) (2 + 2) 2298 2299 If a macro is redefined with a definition that is not effectively the 2300same as the old one, the preprocessor issues a warning and changes the 2301macro to use the new definition. If the new definition is effectively 2302the same, the redefinition is silently ignored. This allows, for 2303instance, two different headers to define a common macro. The 2304preprocessor will only complain if the definitions do not match. 2305 2306 2307File: cpp.info, Node: Directives Within Macro Arguments, Next: Macro Pitfalls, Prev: Undefining and Redefining Macros, Up: Macros 2308 23093.9 Directives Within Macro Arguments 2310===================================== 2311 2312Occasionally it is convenient to use preprocessor directives within the 2313arguments of a macro. The C and C++ standards declare that behavior in 2314these cases is undefined. 2315 2316 Versions of CPP prior to 3.2 would reject such constructs with an 2317error message. This was the only syntactic difference between normal 2318functions and function-like macros, so it seemed attractive to remove 2319this limitation, and people would often be surprised that they could 2320not use macros in this way. Moreover, sometimes people would use 2321conditional compilation in the argument list to a normal library 2322function like `printf', only to find that after a library upgrade 2323`printf' had changed to be a function-like macro, and their code would 2324no longer compile. So from version 3.2 we changed CPP to successfully 2325process arbitrary directives within macro arguments in exactly the same 2326way as it would have processed the directive were the function-like 2327macro invocation not present. 2328 2329 If, within a macro invocation, that macro is redefined, then the new 2330definition takes effect in time for argument pre-expansion, but the 2331original definition is still used for argument replacement. Here is a 2332pathological example: 2333 2334 #define f(x) x x 2335 f (1 2336 #undef f 2337 #define f 2 2338 f) 2339 2340which expands to 2341 2342 1 2 1 2 2343 2344with the semantics described above. 2345 2346 2347File: cpp.info, Node: Macro Pitfalls, Prev: Directives Within Macro Arguments, Up: Macros 2348 23493.10 Macro Pitfalls 2350=================== 2351 2352In this section we describe some special rules that apply to macros and 2353macro expansion, and point out certain cases in which the rules have 2354counter-intuitive consequences that you must watch out for. 2355 2356* Menu: 2357 2358* Misnesting:: 2359* Operator Precedence Problems:: 2360* Swallowing the Semicolon:: 2361* Duplication of Side Effects:: 2362* Self-Referential Macros:: 2363* Argument Prescan:: 2364* Newlines in Arguments:: 2365 2366 2367File: cpp.info, Node: Misnesting, Next: Operator Precedence Problems, Up: Macro Pitfalls 2368 23693.10.1 Misnesting 2370----------------- 2371 2372When a macro is called with arguments, the arguments are substituted 2373into the macro body and the result is checked, together with the rest of 2374the input file, for more macro calls. It is possible to piece together 2375a macro call coming partially from the macro body and partially from the 2376arguments. For example, 2377 2378 #define twice(x) (2*(x)) 2379 #define call_with_1(x) x(1) 2380 call_with_1 (twice) 2381 ==> twice(1) 2382 ==> (2*(1)) 2383 2384 Macro definitions do not have to have balanced parentheses. By 2385writing an unbalanced open parenthesis in a macro body, it is possible 2386to create a macro call that begins inside the macro body but ends 2387outside of it. For example, 2388 2389 #define strange(file) fprintf (file, "%s %d", 2390 ... 2391 strange(stderr) p, 35) 2392 ==> fprintf (stderr, "%s %d", p, 35) 2393 2394 The ability to piece together a macro call can be useful, but the 2395use of unbalanced open parentheses in a macro body is just confusing, 2396and should be avoided. 2397 2398 2399File: cpp.info, Node: Operator Precedence Problems, Next: Swallowing the Semicolon, Prev: Misnesting, Up: Macro Pitfalls 2400 24013.10.2 Operator Precedence Problems 2402----------------------------------- 2403 2404You may have noticed that in most of the macro definition examples shown 2405above, each occurrence of a macro argument name had parentheses around 2406it. In addition, another pair of parentheses usually surround the 2407entire macro definition. Here is why it is best to write macros that 2408way. 2409 2410 Suppose you define a macro as follows, 2411 2412 #define ceil_div(x, y) (x + y - 1) / y 2413 2414whose purpose is to divide, rounding up. (One use for this operation is 2415to compute how many `int' objects are needed to hold a certain number 2416of `char' objects.) Then suppose it is used as follows: 2417 2418 a = ceil_div (b & c, sizeof (int)); 2419 ==> a = (b & c + sizeof (int) - 1) / sizeof (int); 2420 2421This does not do what is intended. The operator-precedence rules of C 2422make it equivalent to this: 2423 2424 a = (b & (c + sizeof (int) - 1)) / sizeof (int); 2425 2426What we want is this: 2427 2428 a = ((b & c) + sizeof (int) - 1)) / sizeof (int); 2429 2430Defining the macro as 2431 2432 #define ceil_div(x, y) ((x) + (y) - 1) / (y) 2433 2434provides the desired result. 2435 2436 Unintended grouping can result in another way. Consider `sizeof 2437ceil_div(1, 2)'. That has the appearance of a C expression that would 2438compute the size of the type of `ceil_div (1, 2)', but in fact it means 2439something very different. Here is what it expands to: 2440 2441 sizeof ((1) + (2) - 1) / (2) 2442 2443This would take the size of an integer and divide it by two. The 2444precedence rules have put the division outside the `sizeof' when it was 2445intended to be inside. 2446 2447 Parentheses around the entire macro definition prevent such problems. 2448Here, then, is the recommended way to define `ceil_div': 2449 2450 #define ceil_div(x, y) (((x) + (y) - 1) / (y)) 2451 2452 2453File: cpp.info, Node: Swallowing the Semicolon, Next: Duplication of Side Effects, Prev: Operator Precedence Problems, Up: Macro Pitfalls 2454 24553.10.3 Swallowing the Semicolon 2456------------------------------- 2457 2458Often it is desirable to define a macro that expands into a compound 2459statement. Consider, for example, the following macro, that advances a 2460pointer (the argument `p' says where to find it) across whitespace 2461characters: 2462 2463 #define SKIP_SPACES(p, limit) \ 2464 { char *lim = (limit); \ 2465 while (p < lim) { \ 2466 if (*p++ != ' ') { \ 2467 p--; break; }}} 2468 2469Here backslash-newline is used to split the macro definition, which must 2470be a single logical line, so that it resembles the way such code would 2471be laid out if not part of a macro definition. 2472 2473 A call to this macro might be `SKIP_SPACES (p, lim)'. Strictly 2474speaking, the call expands to a compound statement, which is a complete 2475statement with no need for a semicolon to end it. However, since it 2476looks like a function call, it minimizes confusion if you can use it 2477like a function call, writing a semicolon afterward, as in `SKIP_SPACES 2478(p, lim);' 2479 2480 This can cause trouble before `else' statements, because the 2481semicolon is actually a null statement. Suppose you write 2482 2483 if (*p != 0) 2484 SKIP_SPACES (p, lim); 2485 else ... 2486 2487The presence of two statements--the compound statement and a null 2488statement--in between the `if' condition and the `else' makes invalid C 2489code. 2490 2491 The definition of the macro `SKIP_SPACES' can be altered to solve 2492this problem, using a `do ... while' statement. Here is how: 2493 2494 #define SKIP_SPACES(p, limit) \ 2495 do { char *lim = (limit); \ 2496 while (p < lim) { \ 2497 if (*p++ != ' ') { \ 2498 p--; break; }}} \ 2499 while (0) 2500 2501 Now `SKIP_SPACES (p, lim);' expands into 2502 2503 do {...} while (0); 2504 2505which is one statement. The loop executes exactly once; most compilers 2506generate no extra code for it. 2507 2508 2509File: cpp.info, Node: Duplication of Side Effects, Next: Self-Referential Macros, Prev: Swallowing the Semicolon, Up: Macro Pitfalls 2510 25113.10.4 Duplication of Side Effects 2512---------------------------------- 2513 2514Many C programs define a macro `min', for "minimum", like this: 2515 2516 #define min(X, Y) ((X) < (Y) ? (X) : (Y)) 2517 2518 When you use this macro with an argument containing a side effect, 2519as shown here, 2520 2521 next = min (x + y, foo (z)); 2522 2523it expands as follows: 2524 2525 next = ((x + y) < (foo (z)) ? (x + y) : (foo (z))); 2526 2527where `x + y' has been substituted for `X' and `foo (z)' for `Y'. 2528 2529 The function `foo' is used only once in the statement as it appears 2530in the program, but the expression `foo (z)' has been substituted twice 2531into the macro expansion. As a result, `foo' might be called two times 2532when the statement is executed. If it has side effects or if it takes 2533a long time to compute, the results might not be what you intended. We 2534say that `min' is an "unsafe" macro. 2535 2536 The best solution to this problem is to define `min' in a way that 2537computes the value of `foo (z)' only once. The C language offers no 2538standard way to do this, but it can be done with GNU extensions as 2539follows: 2540 2541 #define min(X, Y) \ 2542 ({ typeof (X) x_ = (X); \ 2543 typeof (Y) y_ = (Y); \ 2544 (x_ < y_) ? x_ : y_; }) 2545 2546 The `({ ... })' notation produces a compound statement that acts as 2547an expression. Its value is the value of its last statement. This 2548permits us to define local variables and assign each argument to one. 2549The local variables have underscores after their names to reduce the 2550risk of conflict with an identifier of wider scope (it is impossible to 2551avoid this entirely). Now each argument is evaluated exactly once. 2552 2553 If you do not wish to use GNU C extensions, the only solution is to 2554be careful when _using_ the macro `min'. For example, you can 2555calculate the value of `foo (z)', save it in a variable, and use that 2556variable in `min': 2557 2558 #define min(X, Y) ((X) < (Y) ? (X) : (Y)) 2559 ... 2560 { 2561 int tem = foo (z); 2562 next = min (x + y, tem); 2563 } 2564 2565(where we assume that `foo' returns type `int'). 2566 2567 2568File: cpp.info, Node: Self-Referential Macros, Next: Argument Prescan, Prev: Duplication of Side Effects, Up: Macro Pitfalls 2569 25703.10.5 Self-Referential Macros 2571------------------------------ 2572 2573A "self-referential" macro is one whose name appears in its definition. 2574Recall that all macro definitions are rescanned for more macros to 2575replace. If the self-reference were considered a use of the macro, it 2576would produce an infinitely large expansion. To prevent this, the 2577self-reference is not considered a macro call. It is passed into the 2578preprocessor output unchanged. Consider an example: 2579 2580 #define foo (4 + foo) 2581 2582where `foo' is also a variable in your program. 2583 2584 Following the ordinary rules, each reference to `foo' will expand 2585into `(4 + foo)'; then this will be rescanned and will expand into `(4 2586+ (4 + foo))'; and so on until the computer runs out of memory. 2587 2588 The self-reference rule cuts this process short after one step, at 2589`(4 + foo)'. Therefore, this macro definition has the possibly useful 2590effect of causing the program to add 4 to the value of `foo' wherever 2591`foo' is referred to. 2592 2593 In most cases, it is a bad idea to take advantage of this feature. A 2594person reading the program who sees that `foo' is a variable will not 2595expect that it is a macro as well. The reader will come across the 2596identifier `foo' in the program and think its value should be that of 2597the variable `foo', whereas in fact the value is four greater. 2598 2599 One common, useful use of self-reference is to create a macro which 2600expands to itself. If you write 2601 2602 #define EPERM EPERM 2603 2604then the macro `EPERM' expands to `EPERM'. Effectively, it is left 2605alone by the preprocessor whenever it's used in running text. You can 2606tell that it's a macro with `#ifdef'. You might do this if you want to 2607define numeric constants with an `enum', but have `#ifdef' be true for 2608each constant. 2609 2610 If a macro `x' expands to use a macro `y', and the expansion of `y' 2611refers to the macro `x', that is an "indirect self-reference" of `x'. 2612`x' is not expanded in this case either. Thus, if we have 2613 2614 #define x (4 + y) 2615 #define y (2 * x) 2616 2617then `x' and `y' expand as follows: 2618 2619 x ==> (4 + y) 2620 ==> (4 + (2 * x)) 2621 2622 y ==> (2 * x) 2623 ==> (2 * (4 + y)) 2624 2625Each macro is expanded when it appears in the definition of the other 2626macro, but not when it indirectly appears in its own definition. 2627 2628 2629File: cpp.info, Node: Argument Prescan, Next: Newlines in Arguments, Prev: Self-Referential Macros, Up: Macro Pitfalls 2630 26313.10.6 Argument Prescan 2632----------------------- 2633 2634Macro arguments are completely macro-expanded before they are 2635substituted into a macro body, unless they are stringified or pasted 2636with other tokens. After substitution, the entire macro body, including 2637the substituted arguments, is scanned again for macros to be expanded. 2638The result is that the arguments are scanned _twice_ to expand macro 2639calls in them. 2640 2641 Most of the time, this has no effect. If the argument contained any 2642macro calls, they are expanded during the first scan. The result 2643therefore contains no macro calls, so the second scan does not change 2644it. If the argument were substituted as given, with no prescan, the 2645single remaining scan would find the same macro calls and produce the 2646same results. 2647 2648 You might expect the double scan to change the results when a 2649self-referential macro is used in an argument of another macro (*note 2650Self-Referential Macros::): the self-referential macro would be 2651expanded once in the first scan, and a second time in the second scan. 2652However, this is not what happens. The self-references that do not 2653expand in the first scan are marked so that they will not expand in the 2654second scan either. 2655 2656 You might wonder, "Why mention the prescan, if it makes no 2657difference? And why not skip it and make the preprocessor faster?" 2658The answer is that the prescan does make a difference in three special 2659cases: 2660 2661 * Nested calls to a macro. 2662 2663 We say that "nested" calls to a macro occur when a macro's argument 2664 contains a call to that very macro. For example, if `f' is a macro 2665 that expects one argument, `f (f (1))' is a nested pair of calls to 2666 `f'. The desired expansion is made by expanding `f (1)' and 2667 substituting that into the definition of `f'. The prescan causes 2668 the expected result to happen. Without the prescan, `f (1)' itself 2669 would be substituted as an argument, and the inner use of `f' would 2670 appear during the main scan as an indirect self-reference and 2671 would not be expanded. 2672 2673 * Macros that call other macros that stringify or concatenate. 2674 2675 If an argument is stringified or concatenated, the prescan does not 2676 occur. If you _want_ to expand a macro, then stringify or 2677 concatenate its expansion, you can do that by causing one macro to 2678 call another macro that does the stringification or concatenation. 2679 For instance, if you have 2680 2681 #define AFTERX(x) X_ ## x 2682 #define XAFTERX(x) AFTERX(x) 2683 #define TABLESIZE 1024 2684 #define BUFSIZE TABLESIZE 2685 2686 then `AFTERX(BUFSIZE)' expands to `X_BUFSIZE', and 2687 `XAFTERX(BUFSIZE)' expands to `X_1024'. (Not to `X_TABLESIZE'. 2688 Prescan always does a complete expansion.) 2689 2690 * Macros used in arguments, whose expansions contain unshielded 2691 commas. 2692 2693 This can cause a macro expanded on the second scan to be called 2694 with the wrong number of arguments. Here is an example: 2695 2696 #define foo a,b 2697 #define bar(x) lose(x) 2698 #define lose(x) (1 + (x)) 2699 2700 We would like `bar(foo)' to turn into `(1 + (foo))', which would 2701 then turn into `(1 + (a,b))'. Instead, `bar(foo)' expands into 2702 `lose(a,b)', and you get an error because `lose' requires a single 2703 argument. In this case, the problem is easily solved by the same 2704 parentheses that ought to be used to prevent misnesting of 2705 arithmetic operations: 2706 2707 #define foo (a,b) 2708 or 2709 #define bar(x) lose((x)) 2710 2711 The extra pair of parentheses prevents the comma in `foo''s 2712 definition from being interpreted as an argument separator. 2713 2714 2715 2716File: cpp.info, Node: Newlines in Arguments, Prev: Argument Prescan, Up: Macro Pitfalls 2717 27183.10.7 Newlines in Arguments 2719---------------------------- 2720 2721The invocation of a function-like macro can extend over many logical 2722lines. However, in the present implementation, the entire expansion 2723comes out on one line. Thus line numbers emitted by the compiler or 2724debugger refer to the line the invocation started on, which might be 2725different to the line containing the argument causing the problem. 2726 2727 Here is an example illustrating this: 2728 2729 #define ignore_second_arg(a,b,c) a; c 2730 2731 ignore_second_arg (foo (), 2732 ignored (), 2733 syntax error); 2734 2735The syntax error triggered by the tokens `syntax error' results in an 2736error message citing line three--the line of ignore_second_arg-- even 2737though the problematic code comes from line five. 2738 2739 We consider this a bug, and intend to fix it in the near future. 2740 2741 2742File: cpp.info, Node: Conditionals, Next: Diagnostics, Prev: Macros, Up: Top 2743 27444 Conditionals 2745************** 2746 2747A "conditional" is a directive that instructs the preprocessor to 2748select whether or not to include a chunk of code in the final token 2749stream passed to the compiler. Preprocessor conditionals can test 2750arithmetic expressions, or whether a name is defined as a macro, or both 2751simultaneously using the special `defined' operator. 2752 2753 A conditional in the C preprocessor resembles in some ways an `if' 2754statement in C, but it is important to understand the difference between 2755them. The condition in an `if' statement is tested during the 2756execution of your program. Its purpose is to allow your program to 2757behave differently from run to run, depending on the data it is 2758operating on. The condition in a preprocessing conditional directive is 2759tested when your program is compiled. Its purpose is to allow different 2760code to be included in the program depending on the situation at the 2761time of compilation. 2762 2763 However, the distinction is becoming less clear. Modern compilers 2764often do test `if' statements when a program is compiled, if their 2765conditions are known not to vary at run time, and eliminate code which 2766can never be executed. If you can count on your compiler to do this, 2767you may find that your program is more readable if you use `if' 2768statements with constant conditions (perhaps determined by macros). Of 2769course, you can only use this to exclude code, not type definitions or 2770other preprocessing directives, and you can only do it if the code 2771remains syntactically valid when it is not to be used. 2772 2773 GCC version 3 eliminates this kind of never-executed code even when 2774not optimizing. Older versions did it only when optimizing. 2775 2776* Menu: 2777 2778* Conditional Uses:: 2779* Conditional Syntax:: 2780* Deleted Code:: 2781 2782 2783File: cpp.info, Node: Conditional Uses, Next: Conditional Syntax, Up: Conditionals 2784 27854.1 Conditional Uses 2786==================== 2787 2788There are three general reasons to use a conditional. 2789 2790 * A program may need to use different code depending on the machine 2791 or operating system it is to run on. In some cases the code for 2792 one operating system may be erroneous on another operating system; 2793 for example, it might refer to data types or constants that do not 2794 exist on the other system. When this happens, it is not enough to 2795 avoid executing the invalid code. Its mere presence will cause 2796 the compiler to reject the program. With a preprocessing 2797 conditional, the offending code can be effectively excised from 2798 the program when it is not valid. 2799 2800 * You may want to be able to compile the same source file into two 2801 different programs. One version might make frequent time-consuming 2802 consistency checks on its intermediate data, or print the values of 2803 those data for debugging, and the other not. 2804 2805 * A conditional whose condition is always false is one way to 2806 exclude code from the program but keep it as a sort of comment for 2807 future reference. 2808 2809 Simple programs that do not need system-specific logic or complex 2810debugging hooks generally will not need to use preprocessing 2811conditionals. 2812 2813 2814File: cpp.info, Node: Conditional Syntax, Next: Deleted Code, Prev: Conditional Uses, Up: Conditionals 2815 28164.2 Conditional Syntax 2817====================== 2818 2819A conditional in the C preprocessor begins with a "conditional 2820directive": `#if', `#ifdef' or `#ifndef'. 2821 2822* Menu: 2823 2824* Ifdef:: 2825* If:: 2826* Defined:: 2827* Else:: 2828* Elif:: 2829 2830 2831File: cpp.info, Node: Ifdef, Next: If, Up: Conditional Syntax 2832 28334.2.1 Ifdef 2834----------- 2835 2836The simplest sort of conditional is 2837 2838 #ifdef MACRO 2839 2840 CONTROLLED TEXT 2841 2842 #endif /* MACRO */ 2843 2844 This block is called a "conditional group". CONTROLLED TEXT will be 2845included in the output of the preprocessor if and only if MACRO is 2846defined. We say that the conditional "succeeds" if MACRO is defined, 2847"fails" if it is not. 2848 2849 The CONTROLLED TEXT inside of a conditional can include 2850preprocessing directives. They are executed only if the conditional 2851succeeds. You can nest conditional groups inside other conditional 2852groups, but they must be completely nested. In other words, `#endif' 2853always matches the nearest `#ifdef' (or `#ifndef', or `#if'). Also, 2854you cannot start a conditional group in one file and end it in another. 2855 2856 Even if a conditional fails, the CONTROLLED TEXT inside it is still 2857run through initial transformations and tokenization. Therefore, it 2858must all be lexically valid C. Normally the only way this matters is 2859that all comments and string literals inside a failing conditional group 2860must still be properly ended. 2861 2862 The comment following the `#endif' is not required, but it is a good 2863practice if there is a lot of CONTROLLED TEXT, because it helps people 2864match the `#endif' to the corresponding `#ifdef'. Older programs 2865sometimes put MACRO directly after the `#endif' without enclosing it in 2866a comment. This is invalid code according to the C standard. CPP 2867accepts it with a warning. It never affects which `#ifndef' the 2868`#endif' matches. 2869 2870 Sometimes you wish to use some code if a macro is _not_ defined. 2871You can do this by writing `#ifndef' instead of `#ifdef'. One common 2872use of `#ifndef' is to include code only the first time a header file 2873is included. *Note Once-Only Headers::. 2874 2875 Macro definitions can vary between compilations for several reasons. 2876Here are some samples. 2877 2878 * Some macros are predefined on each kind of machine (*note 2879 System-specific Predefined Macros::). This allows you to provide 2880 code specially tuned for a particular machine. 2881 2882 * System header files define more macros, associated with the 2883 features they implement. You can test these macros with 2884 conditionals to avoid using a system feature on a machine where it 2885 is not implemented. 2886 2887 * Macros can be defined or undefined with the `-D' and `-U' command 2888 line options when you compile the program. You can arrange to 2889 compile the same source file into two different programs by 2890 choosing a macro name to specify which program you want, writing 2891 conditionals to test whether or how this macro is defined, and 2892 then controlling the state of the macro with command line options, 2893 perhaps set in the Makefile. *Note Invocation::. 2894 2895 * Your program might have a special header file (often called 2896 `config.h') that is adjusted when the program is compiled. It can 2897 define or not define macros depending on the features of the 2898 system and the desired capabilities of the program. The 2899 adjustment can be automated by a tool such as `autoconf', or done 2900 by hand. 2901 2902 2903File: cpp.info, Node: If, Next: Defined, Prev: Ifdef, Up: Conditional Syntax 2904 29054.2.2 If 2906-------- 2907 2908The `#if' directive allows you to test the value of an arithmetic 2909expression, rather than the mere existence of one macro. Its syntax is 2910 2911 #if EXPRESSION 2912 2913 CONTROLLED TEXT 2914 2915 #endif /* EXPRESSION */ 2916 2917 EXPRESSION is a C expression of integer type, subject to stringent 2918restrictions. It may contain 2919 2920 * Integer constants. 2921 2922 * Character constants, which are interpreted as they would be in 2923 normal code. 2924 2925 * Arithmetic operators for addition, subtraction, multiplication, 2926 division, bitwise operations, shifts, comparisons, and logical 2927 operations (`&&' and `||'). The latter two obey the usual 2928 short-circuiting rules of standard C. 2929 2930 * Macros. All macros in the expression are expanded before actual 2931 computation of the expression's value begins. 2932 2933 * Uses of the `defined' operator, which lets you check whether macros 2934 are defined in the middle of an `#if'. 2935 2936 * Identifiers that are not macros, which are all considered to be the 2937 number zero. This allows you to write `#if MACRO' instead of 2938 `#ifdef MACRO', if you know that MACRO, when defined, will always 2939 have a nonzero value. Function-like macros used without their 2940 function call parentheses are also treated as zero. 2941 2942 In some contexts this shortcut is undesirable. The `-Wundef' 2943 option causes GCC to warn whenever it encounters an identifier 2944 which is not a macro in an `#if'. 2945 2946 The preprocessor does not know anything about types in the language. 2947Therefore, `sizeof' operators are not recognized in `#if', and neither 2948are `enum' constants. They will be taken as identifiers which are not 2949macros, and replaced by zero. In the case of `sizeof', this is likely 2950to cause the expression to be invalid. 2951 2952 The preprocessor calculates the value of EXPRESSION. It carries out 2953all calculations in the widest integer type known to the compiler; on 2954most machines supported by GCC this is 64 bits. This is not the same 2955rule as the compiler uses to calculate the value of a constant 2956expression, and may give different results in some cases. If the value 2957comes out to be nonzero, the `#if' succeeds and the CONTROLLED TEXT is 2958included; otherwise it is skipped. 2959 2960 2961File: cpp.info, Node: Defined, Next: Else, Prev: If, Up: Conditional Syntax 2962 29634.2.3 Defined 2964------------- 2965 2966The special operator `defined' is used in `#if' and `#elif' expressions 2967to test whether a certain name is defined as a macro. `defined NAME' 2968and `defined (NAME)' are both expressions whose value is 1 if NAME is 2969defined as a macro at the current point in the program, and 0 2970otherwise. Thus, `#if defined MACRO' is precisely equivalent to 2971`#ifdef MACRO'. 2972 2973 `defined' is useful when you wish to test more than one macro for 2974existence at once. For example, 2975 2976 #if defined (__vax__) || defined (__ns16000__) 2977 2978would succeed if either of the names `__vax__' or `__ns16000__' is 2979defined as a macro. 2980 2981 Conditionals written like this: 2982 2983 #if defined BUFSIZE && BUFSIZE >= 1024 2984 2985can generally be simplified to just `#if BUFSIZE >= 1024', since if 2986`BUFSIZE' is not defined, it will be interpreted as having the value 2987zero. 2988 2989 If the `defined' operator appears as a result of a macro expansion, 2990the C standard says the behavior is undefined. GNU cpp treats it as a 2991genuine `defined' operator and evaluates it normally. It will warn 2992wherever your code uses this feature if you use the command-line option 2993`-pedantic', since other compilers may handle it differently. 2994 2995 2996File: cpp.info, Node: Else, Next: Elif, Prev: Defined, Up: Conditional Syntax 2997 29984.2.4 Else 2999---------- 3000 3001The `#else' directive can be added to a conditional to provide 3002alternative text to be used if the condition fails. This is what it 3003looks like: 3004 3005 #if EXPRESSION 3006 TEXT-IF-TRUE 3007 #else /* Not EXPRESSION */ 3008 TEXT-IF-FALSE 3009 #endif /* Not EXPRESSION */ 3010 3011If EXPRESSION is nonzero, the TEXT-IF-TRUE is included and the 3012TEXT-IF-FALSE is skipped. If EXPRESSION is zero, the opposite happens. 3013 3014 You can use `#else' with `#ifdef' and `#ifndef', too. 3015 3016 3017File: cpp.info, Node: Elif, Prev: Else, Up: Conditional Syntax 3018 30194.2.5 Elif 3020---------- 3021 3022One common case of nested conditionals is used to check for more than 3023two possible alternatives. For example, you might have 3024 3025 #if X == 1 3026 ... 3027 #else /* X != 1 */ 3028 #if X == 2 3029 ... 3030 #else /* X != 2 */ 3031 ... 3032 #endif /* X != 2 */ 3033 #endif /* X != 1 */ 3034 3035 Another conditional directive, `#elif', allows this to be 3036abbreviated as follows: 3037 3038 #if X == 1 3039 ... 3040 #elif X == 2 3041 ... 3042 #else /* X != 2 and X != 1*/ 3043 ... 3044 #endif /* X != 2 and X != 1*/ 3045 3046 `#elif' stands for "else if". Like `#else', it goes in the middle 3047of a conditional group and subdivides it; it does not require a 3048matching `#endif' of its own. Like `#if', the `#elif' directive 3049includes an expression to be tested. The text following the `#elif' is 3050processed only if the original `#if'-condition failed and the `#elif' 3051condition succeeds. 3052 3053 More than one `#elif' can go in the same conditional group. Then 3054the text after each `#elif' is processed only if the `#elif' condition 3055succeeds after the original `#if' and all previous `#elif' directives 3056within it have failed. 3057 3058 `#else' is allowed after any number of `#elif' directives, but 3059`#elif' may not follow `#else'. 3060 3061 3062File: cpp.info, Node: Deleted Code, Prev: Conditional Syntax, Up: Conditionals 3063 30644.3 Deleted Code 3065================ 3066 3067If you replace or delete a part of the program but want to keep the old 3068code around for future reference, you often cannot simply comment it 3069out. Block comments do not nest, so the first comment inside the old 3070code will end the commenting-out. The probable result is a flood of 3071syntax errors. 3072 3073 One way to avoid this problem is to use an always-false conditional 3074instead. For instance, put `#if 0' before the deleted code and 3075`#endif' after it. This works even if the code being turned off 3076contains conditionals, but they must be entire conditionals (balanced 3077`#if' and `#endif'). 3078 3079 Some people use `#ifdef notdef' instead. This is risky, because 3080`notdef' might be accidentally defined as a macro, and then the 3081conditional would succeed. `#if 0' can be counted on to fail. 3082 3083 Do not use `#if 0' for comments which are not C code. Use a real 3084comment, instead. The interior of `#if 0' must consist of complete 3085tokens; in particular, single-quote characters must balance. Comments 3086often contain unbalanced single-quote characters (known in English as 3087apostrophes). These confuse `#if 0'. They don't confuse `/*'. 3088 3089 3090File: cpp.info, Node: Diagnostics, Next: Line Control, Prev: Conditionals, Up: Top 3091 30925 Diagnostics 3093************* 3094 3095The directive `#error' causes the preprocessor to report a fatal error. 3096The tokens forming the rest of the line following `#error' are used as 3097the error message. 3098 3099 You would use `#error' inside of a conditional that detects a 3100combination of parameters which you know the program does not properly 3101support. For example, if you know that the program will not run 3102properly on a VAX, you might write 3103 3104 #ifdef __vax__ 3105 #error "Won't work on VAXen. See comments at get_last_object." 3106 #endif 3107 3108 If you have several configuration parameters that must be set up by 3109the installation in a consistent way, you can use conditionals to detect 3110an inconsistency and report it with `#error'. For example, 3111 3112 #if !defined(FOO) && defined(BAR) 3113 #error "BAR requires FOO." 3114 #endif 3115 3116 The directive `#warning' is like `#error', but causes the 3117preprocessor to issue a warning and continue preprocessing. The tokens 3118following `#warning' are used as the warning message. 3119 3120 You might use `#warning' in obsolete header files, with a message 3121directing the user to the header file which should be used instead. 3122 3123 Neither `#error' nor `#warning' macro-expands its argument. 3124Internal whitespace sequences are each replaced with a single space. 3125The line must consist of complete tokens. It is wisest to make the 3126argument of these directives be a single string constant; this avoids 3127problems with apostrophes and the like. 3128 3129 3130File: cpp.info, Node: Line Control, Next: Pragmas, Prev: Diagnostics, Up: Top 3131 31326 Line Control 3133************** 3134 3135The C preprocessor informs the C compiler of the location in your source 3136code where each token came from. Presently, this is just the file name 3137and line number. All the tokens resulting from macro expansion are 3138reported as having appeared on the line of the source file where the 3139outermost macro was used. We intend to be more accurate in the future. 3140 3141 If you write a program which generates source code, such as the 3142`bison' parser generator, you may want to adjust the preprocessor's 3143notion of the current file name and line number by hand. Parts of the 3144output from `bison' are generated from scratch, other parts come from a 3145standard parser file. The rest are copied verbatim from `bison''s 3146input. You would like compiler error messages and symbolic debuggers 3147to be able to refer to `bison''s input file. 3148 3149 `bison' or any such program can arrange this by writing `#line' 3150directives into the output file. `#line' is a directive that specifies 3151the original line number and source file name for subsequent input in 3152the current preprocessor input file. `#line' has three variants: 3153 3154`#line LINENUM' 3155 LINENUM is a non-negative decimal integer constant. It specifies 3156 the line number which should be reported for the following line of 3157 input. Subsequent lines are counted from LINENUM. 3158 3159`#line LINENUM FILENAME' 3160 LINENUM is the same as for the first form, and has the same 3161 effect. In addition, FILENAME is a string constant. The 3162 following line and all subsequent lines are reported to come from 3163 the file it specifies, until something else happens to change that. 3164 FILENAME is interpreted according to the normal rules for a string 3165 constant: backslash escapes are interpreted. This is different 3166 from `#include'. 3167 3168 Previous versions of CPP did not interpret escapes in `#line'; we 3169 have changed it because the standard requires they be interpreted, 3170 and most other compilers do. 3171 3172`#line ANYTHING ELSE' 3173 ANYTHING ELSE is checked for macro calls, which are expanded. The 3174 result should match one of the above two forms. 3175 3176 `#line' directives alter the results of the `__FILE__' and 3177`__LINE__' predefined macros from that point on. *Note Standard 3178Predefined Macros::. They do not have any effect on `#include''s idea 3179of the directory containing the current file. This is a change from 3180GCC 2.95. Previously, a file reading 3181 3182 #line 1 "../src/gram.y" 3183 #include "gram.h" 3184 3185 would search for `gram.h' in `../src', then the `-I' chain; the 3186directory containing the physical source file would not be searched. 3187In GCC 3.0 and later, the `#include' is not affected by the presence of 3188a `#line' referring to a different directory. 3189 3190 We made this change because the old behavior caused problems when 3191generated source files were transported between machines. For instance, 3192it is common practice to ship generated parsers with a source release, 3193so that people building the distribution do not need to have yacc or 3194Bison installed. These files frequently have `#line' directives 3195referring to the directory tree of the system where the distribution was 3196created. If GCC tries to search for headers in those directories, the 3197build is likely to fail. 3198 3199 The new behavior can cause failures too, if the generated file is not 3200in the same directory as its source and it attempts to include a header 3201which would be visible searching from the directory containing the 3202source file. However, this problem is easily solved with an additional 3203`-I' switch on the command line. The failures caused by the old 3204semantics could sometimes be corrected only by editing the generated 3205files, which is difficult and error-prone. 3206 3207 3208File: cpp.info, Node: Pragmas, Next: Other Directives, Prev: Line Control, Up: Top 3209 32107 Pragmas 3211********* 3212 3213The `#pragma' directive is the method specified by the C standard for 3214providing additional information to the compiler, beyond what is 3215conveyed in the language itself. Three forms of this directive 3216(commonly known as "pragmas") are specified by the 1999 C standard. A 3217C compiler is free to attach any meaning it likes to other pragmas. 3218 3219 GCC has historically preferred to use extensions to the syntax of the 3220language, such as `__attribute__', for this purpose. However, GCC does 3221define a few pragmas of its own. These mostly have effects on the 3222entire translation unit or source file. 3223 3224 In GCC version 3, all GNU-defined, supported pragmas have been given 3225a `GCC' prefix. This is in line with the `STDC' prefix on all pragmas 3226defined by C99. For backward compatibility, pragmas which were 3227recognized by previous versions are still recognized without the `GCC' 3228prefix, but that usage is deprecated. Some older pragmas are 3229deprecated in their entirety. They are not recognized with the `GCC' 3230prefix. *Note Obsolete Features::. 3231 3232 C99 introduces the `_Pragma' operator. This feature addresses a 3233major problem with `#pragma': being a directive, it cannot be produced 3234as the result of macro expansion. `_Pragma' is an operator, much like 3235`sizeof' or `defined', and can be embedded in a macro. 3236 3237 Its syntax is `_Pragma (STRING-LITERAL)', where STRING-LITERAL can 3238be either a normal or wide-character string literal. It is 3239destringized, by replacing all `\\' with a single `\' and all `\"' with 3240a `"'. The result is then processed as if it had appeared as the right 3241hand side of a `#pragma' directive. For example, 3242 3243 _Pragma ("GCC dependency \"parse.y\"") 3244 3245has the same effect as `#pragma GCC dependency "parse.y"'. The same 3246effect could be achieved using macros, for example 3247 3248 #define DO_PRAGMA(x) _Pragma (#x) 3249 DO_PRAGMA (GCC dependency "parse.y") 3250 3251 The standard is unclear on where a `_Pragma' operator can appear. 3252The preprocessor does not accept it within a preprocessing conditional 3253directive like `#if'. To be safe, you are probably best keeping it out 3254of directives other than `#define', and putting it on a line of its own. 3255 3256 This manual documents the pragmas which are meaningful to the 3257preprocessor itself. Other pragmas are meaningful to the C or C++ 3258compilers. They are documented in the GCC manual. 3259 3260 GCC plugins may provide their own pragmas. 3261 3262`#pragma GCC dependency' 3263 `#pragma GCC dependency' allows you to check the relative dates of 3264 the current file and another file. If the other file is more 3265 recent than the current file, a warning is issued. This is useful 3266 if the current file is derived from the other file, and should be 3267 regenerated. The other file is searched for using the normal 3268 include search path. Optional trailing text can be used to give 3269 more information in the warning message. 3270 3271 #pragma GCC dependency "parse.y" 3272 #pragma GCC dependency "/usr/include/time.h" rerun fixincludes 3273 3274`#pragma GCC poison' 3275 Sometimes, there is an identifier that you want to remove 3276 completely from your program, and make sure that it never creeps 3277 back in. To enforce this, you can "poison" the identifier with 3278 this pragma. `#pragma GCC poison' is followed by a list of 3279 identifiers to poison. If any of those identifiers appears 3280 anywhere in the source after the directive, it is a hard error. 3281 For example, 3282 3283 #pragma GCC poison printf sprintf fprintf 3284 sprintf(some_string, "hello"); 3285 3286 will produce an error. 3287 3288 If a poisoned identifier appears as part of the expansion of a 3289 macro which was defined before the identifier was poisoned, it 3290 will _not_ cause an error. This lets you poison an identifier 3291 without worrying about system headers defining macros that use it. 3292 3293 For example, 3294 3295 #define strrchr rindex 3296 #pragma GCC poison rindex 3297 strrchr(some_string, 'h'); 3298 3299 will not produce an error. 3300 3301`#pragma GCC system_header' 3302 This pragma takes no arguments. It causes the rest of the code in 3303 the current file to be treated as if it came from a system header. 3304 *Note System Headers::. 3305 3306`#pragma GCC warning' 3307`#pragma GCC error' 3308 `#pragma GCC warning "message"' causes the preprocessor to issue a 3309 warning diagnostic with the text `message'. The message contained 3310 in the pragma must be a single string literal. Similarly, 3311 `#pragma GCC error "message"' issues an error message. Unlike the 3312 `#warning' and `#error' directives, these pragmas can be embedded 3313 in preprocessor macros using `_Pragma'. 3314 3315 3316 3317File: cpp.info, Node: Other Directives, Next: Preprocessor Output, Prev: Pragmas, Up: Top 3318 33198 Other Directives 3320****************** 3321 3322The `#ident' directive takes one argument, a string constant. On some 3323systems, that string constant is copied into a special segment of the 3324object file. On other systems, the directive is ignored. The `#sccs' 3325directive is a synonym for `#ident'. 3326 3327 These directives are not part of the C standard, but they are not 3328official GNU extensions either. What historical information we have 3329been able to find, suggests they originated with System V. 3330 3331 The "null directive" consists of a `#' followed by a newline, with 3332only whitespace (including comments) in between. A null directive is 3333understood as a preprocessing directive but has no effect on the 3334preprocessor output. The primary significance of the existence of the 3335null directive is that an input line consisting of just a `#' will 3336produce no output, rather than a line of output containing just a `#'. 3337Supposedly some old C programs contain such lines. 3338 3339 3340File: cpp.info, Node: Preprocessor Output, Next: Traditional Mode, Prev: Other Directives, Up: Top 3341 33429 Preprocessor Output 3343********************* 3344 3345When the C preprocessor is used with the C, C++, or Objective-C 3346compilers, it is integrated into the compiler and communicates a stream 3347of binary tokens directly to the compiler's parser. However, it can 3348also be used in the more conventional standalone mode, where it produces 3349textual output. 3350 3351 The output from the C preprocessor looks much like the input, except 3352that all preprocessing directive lines have been replaced with blank 3353lines and all comments with spaces. Long runs of blank lines are 3354discarded. 3355 3356 The ISO standard specifies that it is implementation defined whether 3357a preprocessor preserves whitespace between tokens, or replaces it with 3358e.g. a single space. In GNU CPP, whitespace between tokens is collapsed 3359to become a single space, with the exception that the first token on a 3360non-directive line is preceded with sufficient spaces that it appears in 3361the same column in the preprocessed output that it appeared in the 3362original source file. This is so the output is easy to read. *Note 3363Differences from previous versions::. CPP does not insert any 3364whitespace where there was none in the original source, except where 3365necessary to prevent an accidental token paste. 3366 3367 Source file name and line number information is conveyed by lines of 3368the form 3369 3370 # LINENUM FILENAME FLAGS 3371 3372These are called "linemarkers". They are inserted as needed into the 3373output (but never within a string or character constant). They mean 3374that the following line originated in file FILENAME at line LINENUM. 3375FILENAME will never contain any non-printing characters; they are 3376replaced with octal escape sequences. 3377 3378 After the file name comes zero or more flags, which are `1', `2', 3379`3', or `4'. If there are multiple flags, spaces separate them. Here 3380is what the flags mean: 3381 3382`1' 3383 This indicates the start of a new file. 3384 3385`2' 3386 This indicates returning to a file (after having included another 3387 file). 3388 3389`3' 3390 This indicates that the following text comes from a system header 3391 file, so certain warnings should be suppressed. 3392 3393`4' 3394 This indicates that the following text should be treated as being 3395 wrapped in an implicit `extern "C"' block. 3396 3397 As an extension, the preprocessor accepts linemarkers in 3398non-assembler input files. They are treated like the corresponding 3399`#line' directive, (*note Line Control::), except that trailing flags 3400are permitted, and are interpreted with the meanings described above. 3401If multiple flags are given, they must be in ascending order. 3402 3403 Some directives may be duplicated in the output of the preprocessor. 3404These are `#ident' (always), `#pragma' (only if the preprocessor does 3405not handle the pragma itself), and `#define' and `#undef' (with certain 3406debugging options). If this happens, the `#' of the directive will 3407always be in the first column, and there will be no space between the 3408`#' and the directive name. If macro expansion happens to generate 3409tokens which might be mistaken for a duplicated directive, a space will 3410be inserted between the `#' and the directive name. 3411 3412 3413File: cpp.info, Node: Traditional Mode, Next: Implementation Details, Prev: Preprocessor Output, Up: Top 3414 341510 Traditional Mode 3416******************* 3417 3418Traditional (pre-standard) C preprocessing is rather different from the 3419preprocessing specified by the standard. When GCC is given the 3420`-traditional-cpp' option, it attempts to emulate a traditional 3421preprocessor. 3422 3423 GCC versions 3.2 and later only support traditional mode semantics in 3424the preprocessor, and not in the compiler front ends. This chapter 3425outlines the traditional preprocessor semantics we implemented. 3426 3427 The implementation does not correspond precisely to the behavior of 3428earlier versions of GCC, nor to any true traditional preprocessor. 3429After all, inconsistencies among traditional implementations were a 3430major motivation for C standardization. However, we intend that it 3431should be compatible with true traditional preprocessors in all ways 3432that actually matter. 3433 3434* Menu: 3435 3436* Traditional lexical analysis:: 3437* Traditional macros:: 3438* Traditional miscellany:: 3439* Traditional warnings:: 3440 3441 3442File: cpp.info, Node: Traditional lexical analysis, Next: Traditional macros, Up: Traditional Mode 3443 344410.1 Traditional lexical analysis 3445================================= 3446 3447The traditional preprocessor does not decompose its input into tokens 3448the same way a standards-conforming preprocessor does. The input is 3449simply treated as a stream of text with minimal internal form. 3450 3451 This implementation does not treat trigraphs (*note trigraphs::) 3452specially since they were an invention of the standards committee. It 3453handles arbitrarily-positioned escaped newlines properly and splices 3454the lines as you would expect; many traditional preprocessors did not 3455do this. 3456 3457 The form of horizontal whitespace in the input file is preserved in 3458the output. In particular, hard tabs remain hard tabs. This can be 3459useful if, for example, you are preprocessing a Makefile. 3460 3461 Traditional CPP only recognizes C-style block comments, and treats 3462the `/*' sequence as introducing a comment only if it lies outside 3463quoted text. Quoted text is introduced by the usual single and double 3464quotes, and also by an initial `<' in a `#include' directive. 3465 3466 Traditionally, comments are completely removed and are not replaced 3467with a space. Since a traditional compiler does its own tokenization 3468of the output of the preprocessor, this means that comments can 3469effectively be used as token paste operators. However, comments behave 3470like separators for text handled by the preprocessor itself, since it 3471doesn't re-lex its input. For example, in 3472 3473 #if foo/**/bar 3474 3475`foo' and `bar' are distinct identifiers and expanded separately if 3476they happen to be macros. In other words, this directive is equivalent 3477to 3478 3479 #if foo bar 3480 3481rather than 3482 3483 #if foobar 3484 3485 Generally speaking, in traditional mode an opening quote need not 3486have a matching closing quote. In particular, a macro may be defined 3487with replacement text that contains an unmatched quote. Of course, if 3488you attempt to compile preprocessed output containing an unmatched quote 3489you will get a syntax error. 3490 3491 However, all preprocessing directives other than `#define' require 3492matching quotes. For example: 3493 3494 #define m This macro's fine and has an unmatched quote 3495 "/* This is not a comment. */ 3496 /* This is a comment. The following #include directive 3497 is ill-formed. */ 3498 #include <stdio.h 3499 3500 Just as for the ISO preprocessor, what would be a closing quote can 3501be escaped with a backslash to prevent the quoted text from closing. 3502 3503 3504File: cpp.info, Node: Traditional macros, Next: Traditional miscellany, Prev: Traditional lexical analysis, Up: Traditional Mode 3505 350610.2 Traditional macros 3507======================= 3508 3509The major difference between traditional and ISO macros is that the 3510former expand to text rather than to a token sequence. CPP removes all 3511leading and trailing horizontal whitespace from a macro's replacement 3512text before storing it, but preserves the form of internal whitespace. 3513 3514 One consequence is that it is legitimate for the replacement text to 3515contain an unmatched quote (*note Traditional lexical analysis::). An 3516unclosed string or character constant continues into the text following 3517the macro call. Similarly, the text at the end of a macro's expansion 3518can run together with the text after the macro invocation to produce a 3519single token. 3520 3521 Normally comments are removed from the replacement text after the 3522macro is expanded, but if the `-CC' option is passed on the command 3523line comments are preserved. (In fact, the current implementation 3524removes comments even before saving the macro replacement text, but it 3525careful to do it in such a way that the observed effect is identical 3526even in the function-like macro case.) 3527 3528 The ISO stringification operator `#' and token paste operator `##' 3529have no special meaning. As explained later, an effect similar to 3530these operators can be obtained in a different way. Macro names that 3531are embedded in quotes, either from the main file or after macro 3532replacement, do not expand. 3533 3534 CPP replaces an unquoted object-like macro name with its replacement 3535text, and then rescans it for further macros to replace. Unlike 3536standard macro expansion, traditional macro expansion has no provision 3537to prevent recursion. If an object-like macro appears unquoted in its 3538replacement text, it will be replaced again during the rescan pass, and 3539so on _ad infinitum_. GCC detects when it is expanding recursive 3540macros, emits an error message, and continues after the offending macro 3541invocation. 3542 3543 #define PLUS + 3544 #define INC(x) PLUS+x 3545 INC(foo); 3546 ==> ++foo; 3547 3548 Function-like macros are similar in form but quite different in 3549behavior to their ISO counterparts. Their arguments are contained 3550within parentheses, are comma-separated, and can cross physical lines. 3551Commas within nested parentheses are not treated as argument 3552separators. Similarly, a quote in an argument cannot be left unclosed; 3553a following comma or parenthesis that comes before the closing quote is 3554treated like any other character. There is no facility for handling 3555variadic macros. 3556 3557 This implementation removes all comments from macro arguments, unless 3558the `-C' option is given. The form of all other horizontal whitespace 3559in arguments is preserved, including leading and trailing whitespace. 3560In particular 3561 3562 f( ) 3563 3564is treated as an invocation of the macro `f' with a single argument 3565consisting of a single space. If you want to invoke a function-like 3566macro that takes no arguments, you must not leave any whitespace 3567between the parentheses. 3568 3569 If a macro argument crosses a new line, the new line is replaced with 3570a space when forming the argument. If the previous line contained an 3571unterminated quote, the following line inherits the quoted state. 3572 3573 Traditional preprocessors replace parameters in the replacement text 3574with their arguments regardless of whether the parameters are within 3575quotes or not. This provides a way to stringize arguments. For example 3576 3577 #define str(x) "x" 3578 str(/* A comment */some text ) 3579 ==> "some text " 3580 3581Note that the comment is removed, but that the trailing space is 3582preserved. Here is an example of using a comment to effect token 3583pasting. 3584 3585 #define suffix(x) foo_/**/x 3586 suffix(bar) 3587 ==> foo_bar 3588 3589 3590File: cpp.info, Node: Traditional miscellany, Next: Traditional warnings, Prev: Traditional macros, Up: Traditional Mode 3591 359210.3 Traditional miscellany 3593=========================== 3594 3595Here are some things to be aware of when using the traditional 3596preprocessor. 3597 3598 * Preprocessing directives are recognized only when their leading 3599 `#' appears in the first column. There can be no whitespace 3600 between the beginning of the line and the `#', but whitespace can 3601 follow the `#'. 3602 3603 * A true traditional C preprocessor does not recognize `#error' or 3604 `#pragma', and may not recognize `#elif'. CPP supports all the 3605 directives in traditional mode that it supports in ISO mode, 3606 including extensions, with the exception that the effects of 3607 `#pragma GCC poison' are undefined. 3608 3609 * __STDC__ is not defined. 3610 3611 * If you use digraphs the behavior is undefined. 3612 3613 * If a line that looks like a directive appears within macro 3614 arguments, the behavior is undefined. 3615 3616 3617 3618File: cpp.info, Node: Traditional warnings, Prev: Traditional miscellany, Up: Traditional Mode 3619 362010.4 Traditional warnings 3621========================= 3622 3623You can request warnings about features that did not exist, or worked 3624differently, in traditional C with the `-Wtraditional' option. GCC 3625does not warn about features of ISO C which you must use when you are 3626using a conforming compiler, such as the `#' and `##' operators. 3627 3628 Presently `-Wtraditional' warns about: 3629 3630 * Macro parameters that appear within string literals in the macro 3631 body. In traditional C macro replacement takes place within 3632 string literals, but does not in ISO C. 3633 3634 * In traditional C, some preprocessor directives did not exist. 3635 Traditional preprocessors would only consider a line to be a 3636 directive if the `#' appeared in column 1 on the line. Therefore 3637 `-Wtraditional' warns about directives that traditional C 3638 understands but would ignore because the `#' does not appear as the 3639 first character on the line. It also suggests you hide directives 3640 like `#pragma' not understood by traditional C by indenting them. 3641 Some traditional implementations would not recognize `#elif', so it 3642 suggests avoiding it altogether. 3643 3644 * A function-like macro that appears without an argument list. In 3645 some traditional preprocessors this was an error. In ISO C it 3646 merely means that the macro is not expanded. 3647 3648 * The unary plus operator. This did not exist in traditional C. 3649 3650 * The `U' and `LL' integer constant suffixes, which were not 3651 available in traditional C. (Traditional C does support the `L' 3652 suffix for simple long integer constants.) You are not warned 3653 about uses of these suffixes in macros defined in system headers. 3654 For instance, `UINT_MAX' may well be defined as `4294967295U', but 3655 you will not be warned if you use `UINT_MAX'. 3656 3657 You can usually avoid the warning, and the related warning about 3658 constants which are so large that they are unsigned, by writing the 3659 integer constant in question in hexadecimal, with no U suffix. 3660 Take care, though, because this gives the wrong result in exotic 3661 cases. 3662 3663 3664File: cpp.info, Node: Implementation Details, Next: Invocation, Prev: Traditional Mode, Up: Top 3665 366611 Implementation Details 3667************************* 3668 3669Here we document details of how the preprocessor's implementation 3670affects its user-visible behavior. You should try to avoid undue 3671reliance on behavior described here, as it is possible that it will 3672change subtly in future implementations. 3673 3674 Also documented here are obsolete features and changes from previous 3675versions of CPP. 3676 3677* Menu: 3678 3679* Implementation-defined behavior:: 3680* Implementation limits:: 3681* Obsolete Features:: 3682* Differences from previous versions:: 3683 3684 3685File: cpp.info, Node: Implementation-defined behavior, Next: Implementation limits, Up: Implementation Details 3686 368711.1 Implementation-defined behavior 3688==================================== 3689 3690This is how CPP behaves in all the cases which the C standard describes 3691as "implementation-defined". This term means that the implementation 3692is free to do what it likes, but must document its choice and stick to 3693it. 3694 3695 * The mapping of physical source file multi-byte characters to the 3696 execution character set. 3697 3698 The input character set can be specified using the 3699 `-finput-charset' option, while the execution character set may be 3700 controlled using the `-fexec-charset' and `-fwide-exec-charset' 3701 options. 3702 3703 * Identifier characters. The C and C++ standards allow identifiers 3704 to be composed of `_' and the alphanumeric characters. C++ and 3705 C99 also allow universal character names, and C99 further permits 3706 implementation-defined characters. GCC currently only permits 3707 universal character names if `-fextended-identifiers' is used, 3708 because the implementation of universal character names in 3709 identifiers is experimental. 3710 3711 GCC allows the `$' character in identifiers as an extension for 3712 most targets. This is true regardless of the `std=' switch, since 3713 this extension cannot conflict with standards-conforming programs. 3714 When preprocessing assembler, however, dollars are not identifier 3715 characters by default. 3716 3717 Currently the targets that by default do not permit `$' are AVR, 3718 IP2K, MMIX, MIPS Irix 3, ARM aout, and PowerPC targets for the AIX 3719 operating system. 3720 3721 You can override the default with `-fdollars-in-identifiers' or 3722 `fno-dollars-in-identifiers'. *Note fdollars-in-identifiers::. 3723 3724 * Non-empty sequences of whitespace characters. 3725 3726 In textual output, each whitespace sequence is collapsed to a 3727 single space. For aesthetic reasons, the first token on each 3728 non-directive line of output is preceded with sufficient spaces 3729 that it appears in the same column as it did in the original 3730 source file. 3731 3732 * The numeric value of character constants in preprocessor 3733 expressions. 3734 3735 The preprocessor and compiler interpret character constants in the 3736 same way; i.e. escape sequences such as `\a' are given the values 3737 they would have on the target machine. 3738 3739 The compiler evaluates a multi-character character constant a 3740 character at a time, shifting the previous value left by the 3741 number of bits per target character, and then or-ing in the 3742 bit-pattern of the new character truncated to the width of a 3743 target character. The final bit-pattern is given type `int', and 3744 is therefore signed, regardless of whether single characters are 3745 signed or not (a slight change from versions 3.1 and earlier of 3746 GCC). If there are more characters in the constant than would fit 3747 in the target `int' the compiler issues a warning, and the excess 3748 leading characters are ignored. 3749 3750 For example, `'ab'' for a target with an 8-bit `char' would be 3751 interpreted as 3752 `(int) ((unsigned char) 'a' * 256 + (unsigned char) 'b')', and 3753 `'\234a'' as 3754 `(int) ((unsigned char) '\234' * 256 + (unsigned char) 'a')'. 3755 3756 * Source file inclusion. 3757 3758 For a discussion on how the preprocessor locates header files, 3759 *note Include Operation::. 3760 3761 * Interpretation of the filename resulting from a macro-expanded 3762 `#include' directive. 3763 3764 *Note Computed Includes::. 3765 3766 * Treatment of a `#pragma' directive that after macro-expansion 3767 results in a standard pragma. 3768 3769 No macro expansion occurs on any `#pragma' directive line, so the 3770 question does not arise. 3771 3772 Note that GCC does not yet implement any of the standard pragmas. 3773 3774 3775 3776File: cpp.info, Node: Implementation limits, Next: Obsolete Features, Prev: Implementation-defined behavior, Up: Implementation Details 3777 377811.2 Implementation limits 3779========================== 3780 3781CPP has a small number of internal limits. This section lists the 3782limits which the C standard requires to be no lower than some minimum, 3783and all the others known. It is intended that there should be as few 3784limits as possible. If you encounter an undocumented or inconvenient 3785limit, please report that as a bug. *Note Reporting Bugs: (gcc)Bugs. 3786 3787 Where we say something is limited "only by available memory", that 3788means that internal data structures impose no intrinsic limit, and space 3789is allocated with `malloc' or equivalent. The actual limit will 3790therefore depend on many things, such as the size of other things 3791allocated by the compiler at the same time, the amount of memory 3792consumed by other processes on the same computer, etc. 3793 3794 * Nesting levels of `#include' files. 3795 3796 We impose an arbitrary limit of 200 levels, to avoid runaway 3797 recursion. The standard requires at least 15 levels. 3798 3799 * Nesting levels of conditional inclusion. 3800 3801 The C standard mandates this be at least 63. CPP is limited only 3802 by available memory. 3803 3804 * Levels of parenthesized expressions within a full expression. 3805 3806 The C standard requires this to be at least 63. In preprocessor 3807 conditional expressions, it is limited only by available memory. 3808 3809 * Significant initial characters in an identifier or macro name. 3810 3811 The preprocessor treats all characters as significant. The C 3812 standard requires only that the first 63 be significant. 3813 3814 * Number of macros simultaneously defined in a single translation 3815 unit. 3816 3817 The standard requires at least 4095 be possible. CPP is limited 3818 only by available memory. 3819 3820 * Number of parameters in a macro definition and arguments in a 3821 macro call. 3822 3823 We allow `USHRT_MAX', which is no smaller than 65,535. The minimum 3824 required by the standard is 127. 3825 3826 * Number of characters on a logical source line. 3827 3828 The C standard requires a minimum of 4096 be permitted. CPP places 3829 no limits on this, but you may get incorrect column numbers 3830 reported in diagnostics for lines longer than 65,535 characters. 3831 3832 * Maximum size of a source file. 3833 3834 The standard does not specify any lower limit on the maximum size 3835 of a source file. GNU cpp maps files into memory, so it is 3836 limited by the available address space. This is generally at 3837 least two gigabytes. Depending on the operating system, the size 3838 of physical memory may or may not be a limitation. 3839 3840 3841 3842File: cpp.info, Node: Obsolete Features, Next: Differences from previous versions, Prev: Implementation limits, Up: Implementation Details 3843 384411.3 Obsolete Features 3845====================== 3846 3847CPP has some features which are present mainly for compatibility with 3848older programs. We discourage their use in new code. In some cases, 3849we plan to remove the feature in a future version of GCC. 3850 385111.3.1 Assertions 3852----------------- 3853 3854"Assertions" are a deprecated alternative to macros in writing 3855conditionals to test what sort of computer or system the compiled 3856program will run on. Assertions are usually predefined, but you can 3857define them with preprocessing directives or command-line options. 3858 3859 Assertions were intended to provide a more systematic way to describe 3860the compiler's target system and we added them for compatibility with 3861existing compilers. In practice they are just as unpredictable as the 3862system-specific predefined macros. In addition, they are not part of 3863any standard, and only a few compilers support them. Therefore, the 3864use of assertions is *less* portable than the use of system-specific 3865predefined macros. We recommend you do not use them at all. 3866 3867 An assertion looks like this: 3868 3869 #PREDICATE (ANSWER) 3870 3871PREDICATE must be a single identifier. ANSWER can be any sequence of 3872tokens; all characters are significant except for leading and trailing 3873whitespace, and differences in internal whitespace sequences are 3874ignored. (This is similar to the rules governing macro redefinition.) 3875Thus, `(x + y)' is different from `(x+y)' but equivalent to 3876`( x + y )'. Parentheses do not nest inside an answer. 3877 3878 To test an assertion, you write it in an `#if'. For example, this 3879conditional succeeds if either `vax' or `ns16000' has been asserted as 3880an answer for `machine'. 3881 3882 #if #machine (vax) || #machine (ns16000) 3883 3884You can test whether _any_ answer is asserted for a predicate by 3885omitting the answer in the conditional: 3886 3887 #if #machine 3888 3889 Assertions are made with the `#assert' directive. Its sole argument 3890is the assertion to make, without the leading `#' that identifies 3891assertions in conditionals. 3892 3893 #assert PREDICATE (ANSWER) 3894 3895You may make several assertions with the same predicate and different 3896answers. Subsequent assertions do not override previous ones for the 3897same predicate. All the answers for any given predicate are 3898simultaneously true. 3899 3900 Assertions can be canceled with the `#unassert' directive. It has 3901the same syntax as `#assert'. In that form it cancels only the answer 3902which was specified on the `#unassert' line; other answers for that 3903predicate remain true. You can cancel an entire predicate by leaving 3904out the answer: 3905 3906 #unassert PREDICATE 3907 3908In either form, if no such assertion has been made, `#unassert' has no 3909effect. 3910 3911 You can also make or cancel assertions using command line options. 3912*Note Invocation::. 3913 3914 3915File: cpp.info, Node: Differences from previous versions, Prev: Obsolete Features, Up: Implementation Details 3916 391711.4 Differences from previous versions 3918======================================= 3919 3920This section details behavior which has changed from previous versions 3921of CPP. We do not plan to change it again in the near future, but we 3922do not promise not to, either. 3923 3924 The "previous versions" discussed here are 2.95 and before. The 3925behavior of GCC 3.0 is mostly the same as the behavior of the widely 3926used 2.96 and 2.97 development snapshots. Where there are differences, 3927they generally represent bugs in the snapshots. 3928 3929 * -I- deprecated 3930 3931 This option has been deprecated in 4.0. `-iquote' is meant to 3932 replace the need for this option. 3933 3934 * Order of evaluation of `#' and `##' operators 3935 3936 The standard does not specify the order of evaluation of a chain of 3937 `##' operators, nor whether `#' is evaluated before, after, or at 3938 the same time as `##'. You should therefore not write any code 3939 which depends on any specific ordering. It is possible to 3940 guarantee an ordering, if you need one, by suitable use of nested 3941 macros. 3942 3943 An example of where this might matter is pasting the arguments `1', 3944 `e' and `-2'. This would be fine for left-to-right pasting, but 3945 right-to-left pasting would produce an invalid token `e-2'. 3946 3947 GCC 3.0 evaluates `#' and `##' at the same time and strictly left 3948 to right. Older versions evaluated all `#' operators first, then 3949 all `##' operators, in an unreliable order. 3950 3951 * The form of whitespace between tokens in preprocessor output 3952 3953 *Note Preprocessor Output::, for the current textual format. This 3954 is also the format used by stringification. Normally, the 3955 preprocessor communicates tokens directly to the compiler's 3956 parser, and whitespace does not come up at all. 3957 3958 Older versions of GCC preserved all whitespace provided by the 3959 user and inserted lots more whitespace of their own, because they 3960 could not accurately predict when extra spaces were needed to 3961 prevent accidental token pasting. 3962 3963 * Optional argument when invoking rest argument macros 3964 3965 As an extension, GCC permits you to omit the variable arguments 3966 entirely when you use a variable argument macro. This is 3967 forbidden by the 1999 C standard, and will provoke a pedantic 3968 warning with GCC 3.0. Previous versions accepted it silently. 3969 3970 * `##' swallowing preceding text in rest argument macros 3971 3972 Formerly, in a macro expansion, if `##' appeared before a variable 3973 arguments parameter, and the set of tokens specified for that 3974 argument in the macro invocation was empty, previous versions of 3975 CPP would back up and remove the preceding sequence of 3976 non-whitespace characters (*not* the preceding token). This 3977 extension is in direct conflict with the 1999 C standard and has 3978 been drastically pared back. 3979 3980 In the current version of the preprocessor, if `##' appears between 3981 a comma and a variable arguments parameter, and the variable 3982 argument is omitted entirely, the comma will be removed from the 3983 expansion. If the variable argument is empty, or the token before 3984 `##' is not a comma, then `##' behaves as a normal token paste. 3985 3986 * `#line' and `#include' 3987 3988 The `#line' directive used to change GCC's notion of the 3989 "directory containing the current file", used by `#include' with a 3990 double-quoted header file name. In 3.0 and later, it does not. 3991 *Note Line Control::, for further explanation. 3992 3993 * Syntax of `#line' 3994 3995 In GCC 2.95 and previous, the string constant argument to `#line' 3996 was treated the same way as the argument to `#include': backslash 3997 escapes were not honored, and the string ended at the second `"'. 3998 This is not compliant with the C standard. In GCC 3.0, an attempt 3999 was made to correct the behavior, so that the string was treated 4000 as a real string constant, but it turned out to be buggy. In 3.1, 4001 the bugs have been fixed. (We are not fixing the bugs in 3.0 4002 because they affect relatively few people and the fix is quite 4003 invasive.) 4004 4005 4006 4007File: cpp.info, Node: Invocation, Next: Environment Variables, Prev: Implementation Details, Up: Top 4008 400912 Invocation 4010************* 4011 4012Most often when you use the C preprocessor you will not have to invoke 4013it explicitly: the C compiler will do so automatically. However, the 4014preprocessor is sometimes useful on its own. All the options listed 4015here are also acceptable to the C compiler and have the same meaning, 4016except that the C compiler has different rules for specifying the output 4017file. 4018 4019 _Note:_ Whether you use the preprocessor by way of `gcc' or `cpp', 4020the "compiler driver" is run first. This program's purpose is to 4021translate your command into invocations of the programs that do the 4022actual work. Their command line interfaces are similar but not 4023identical to the documented interface, and may change without notice. 4024 4025 The C preprocessor expects two file names as arguments, INFILE and 4026OUTFILE. The preprocessor reads INFILE together with any other files 4027it specifies with `#include'. All the output generated by the combined 4028input files is written in OUTFILE. 4029 4030 Either INFILE or OUTFILE may be `-', which as INFILE means to read 4031from standard input and as OUTFILE means to write to standard output. 4032Also, if either file is omitted, it means the same as if `-' had been 4033specified for that file. 4034 4035 Unless otherwise noted, or the option ends in `=', all options which 4036take an argument may have that argument appear either immediately after 4037the option, or with a space between option and argument: `-Ifoo' and 4038`-I foo' have the same effect. 4039 4040 Many options have multi-letter names; therefore multiple 4041single-letter options may _not_ be grouped: `-dM' is very different from 4042`-d -M'. 4043 4044`-D NAME' 4045 Predefine NAME as a macro, with definition `1'. 4046 4047`-D NAME=DEFINITION' 4048 The contents of DEFINITION are tokenized and processed as if they 4049 appeared during translation phase three in a `#define' directive. 4050 In particular, the definition will be truncated by embedded 4051 newline characters. 4052 4053 If you are invoking the preprocessor from a shell or shell-like 4054 program you may need to use the shell's quoting syntax to protect 4055 characters such as spaces that have a meaning in the shell syntax. 4056 4057 If you wish to define a function-like macro on the command line, 4058 write its argument list with surrounding parentheses before the 4059 equals sign (if any). Parentheses are meaningful to most shells, 4060 so you will need to quote the option. With `sh' and `csh', 4061 `-D'NAME(ARGS...)=DEFINITION'' works. 4062 4063 `-D' and `-U' options are processed in the order they are given on 4064 the command line. All `-imacros FILE' and `-include FILE' options 4065 are processed after all `-D' and `-U' options. 4066 4067`-U NAME' 4068 Cancel any previous definition of NAME, either built in or 4069 provided with a `-D' option. 4070 4071`-undef' 4072 Do not predefine any system-specific or GCC-specific macros. The 4073 standard predefined macros remain defined. *Note Standard 4074 Predefined Macros::. 4075 4076`-I DIR' 4077 Add the directory DIR to the list of directories to be searched 4078 for header files. *Note Search Path::. Directories named by `-I' 4079 are searched before the standard system include directories. If 4080 the directory DIR is a standard system include directory, the 4081 option is ignored to ensure that the default search order for 4082 system directories and the special treatment of system headers are 4083 not defeated (*note System Headers::) . If DIR begins with `=', 4084 then the `=' will be replaced by the sysroot prefix; see 4085 `--sysroot' and `-isysroot'. 4086 4087`-o FILE' 4088 Write output to FILE. This is the same as specifying FILE as the 4089 second non-option argument to `cpp'. `gcc' has a different 4090 interpretation of a second non-option argument, so you must use 4091 `-o' to specify the output file. 4092 4093`-Wall' 4094 Turns on all optional warnings which are desirable for normal code. 4095 At present this is `-Wcomment', `-Wtrigraphs', `-Wmultichar' and a 4096 warning about integer promotion causing a change of sign in `#if' 4097 expressions. Note that many of the preprocessor's warnings are on 4098 by default and have no options to control them. 4099 4100`-Wcomment' 4101`-Wcomments' 4102 Warn whenever a comment-start sequence `/*' appears in a `/*' 4103 comment, or whenever a backslash-newline appears in a `//' comment. 4104 (Both forms have the same effect.) 4105 4106`-Wtrigraphs' 4107 Most trigraphs in comments cannot affect the meaning of the 4108 program. However, a trigraph that would form an escaped newline 4109 (`??/' at the end of a line) can, by changing where the comment 4110 begins or ends. Therefore, only trigraphs that would form escaped 4111 newlines produce warnings inside a comment. 4112 4113 This option is implied by `-Wall'. If `-Wall' is not given, this 4114 option is still enabled unless trigraphs are enabled. To get 4115 trigraph conversion without warnings, but get the other `-Wall' 4116 warnings, use `-trigraphs -Wall -Wno-trigraphs'. 4117 4118`-Wtraditional' 4119 Warn about certain constructs that behave differently in 4120 traditional and ISO C. Also warn about ISO C constructs that have 4121 no traditional C equivalent, and problematic constructs which 4122 should be avoided. *Note Traditional Mode::. 4123 4124`-Wundef' 4125 Warn whenever an identifier which is not a macro is encountered in 4126 an `#if' directive, outside of `defined'. Such identifiers are 4127 replaced with zero. 4128 4129`-Wunused-macros' 4130 Warn about macros defined in the main file that are unused. A 4131 macro is "used" if it is expanded or tested for existence at least 4132 once. The preprocessor will also warn if the macro has not been 4133 used at the time it is redefined or undefined. 4134 4135 Built-in macros, macros defined on the command line, and macros 4136 defined in include files are not warned about. 4137 4138 _Note:_ If a macro is actually used, but only used in skipped 4139 conditional blocks, then CPP will report it as unused. To avoid 4140 the warning in such a case, you might improve the scope of the 4141 macro's definition by, for example, moving it into the first 4142 skipped block. Alternatively, you could provide a dummy use with 4143 something like: 4144 4145 #if defined the_macro_causing_the_warning 4146 #endif 4147 4148`-Wendif-labels' 4149 Warn whenever an `#else' or an `#endif' are followed by text. 4150 This usually happens in code of the form 4151 4152 #if FOO 4153 ... 4154 #else FOO 4155 ... 4156 #endif FOO 4157 4158 The second and third `FOO' should be in comments, but often are not 4159 in older programs. This warning is on by default. 4160 4161`-Werror' 4162 Make all warnings into hard errors. Source code which triggers 4163 warnings will be rejected. 4164 4165`-Wsystem-headers' 4166 Issue warnings for code in system headers. These are normally 4167 unhelpful in finding bugs in your own code, therefore suppressed. 4168 If you are responsible for the system library, you may want to see 4169 them. 4170 4171`-w' 4172 Suppress all warnings, including those which GNU CPP issues by 4173 default. 4174 4175`-pedantic' 4176 Issue all the mandatory diagnostics listed in the C standard. 4177 Some of them are left out by default, since they trigger 4178 frequently on harmless code. 4179 4180`-pedantic-errors' 4181 Issue all the mandatory diagnostics, and make all mandatory 4182 diagnostics into errors. This includes mandatory diagnostics that 4183 GCC issues without `-pedantic' but treats as warnings. 4184 4185`-M' 4186 Instead of outputting the result of preprocessing, output a rule 4187 suitable for `make' describing the dependencies of the main source 4188 file. The preprocessor outputs one `make' rule containing the 4189 object file name for that source file, a colon, and the names of 4190 all the included files, including those coming from `-include' or 4191 `-imacros' command line options. 4192 4193 Unless specified explicitly (with `-MT' or `-MQ'), the object file 4194 name consists of the name of the source file with any suffix 4195 replaced with object file suffix and with any leading directory 4196 parts removed. If there are many included files then the rule is 4197 split into several lines using `\'-newline. The rule has no 4198 commands. 4199 4200 This option does not suppress the preprocessor's debug output, 4201 such as `-dM'. To avoid mixing such debug output with the 4202 dependency rules you should explicitly specify the dependency 4203 output file with `-MF', or use an environment variable like 4204 `DEPENDENCIES_OUTPUT' (*note Environment Variables::). Debug 4205 output will still be sent to the regular output stream as normal. 4206 4207 Passing `-M' to the driver implies `-E', and suppresses warnings 4208 with an implicit `-w'. 4209 4210`-MM' 4211 Like `-M' but do not mention header files that are found in system 4212 header directories, nor header files that are included, directly 4213 or indirectly, from such a header. 4214 4215 This implies that the choice of angle brackets or double quotes in 4216 an `#include' directive does not in itself determine whether that 4217 header will appear in `-MM' dependency output. This is a slight 4218 change in semantics from GCC versions 3.0 and earlier. 4219 4220`-MF FILE' 4221 When used with `-M' or `-MM', specifies a file to write the 4222 dependencies to. If no `-MF' switch is given the preprocessor 4223 sends the rules to the same place it would have sent preprocessed 4224 output. 4225 4226 When used with the driver options `-MD' or `-MMD', `-MF' overrides 4227 the default dependency output file. 4228 4229`-MG' 4230 In conjunction with an option such as `-M' requesting dependency 4231 generation, `-MG' assumes missing header files are generated files 4232 and adds them to the dependency list without raising an error. 4233 The dependency filename is taken directly from the `#include' 4234 directive without prepending any path. `-MG' also suppresses 4235 preprocessed output, as a missing header file renders this useless. 4236 4237 This feature is used in automatic updating of makefiles. 4238 4239`-MP' 4240 This option instructs CPP to add a phony target for each dependency 4241 other than the main file, causing each to depend on nothing. These 4242 dummy rules work around errors `make' gives if you remove header 4243 files without updating the `Makefile' to match. 4244 4245 This is typical output: 4246 4247 test.o: test.c test.h 4248 4249 test.h: 4250 4251`-MT TARGET' 4252 Change the target of the rule emitted by dependency generation. By 4253 default CPP takes the name of the main input file, deletes any 4254 directory components and any file suffix such as `.c', and appends 4255 the platform's usual object suffix. The result is the target. 4256 4257 An `-MT' option will set the target to be exactly the string you 4258 specify. If you want multiple targets, you can specify them as a 4259 single argument to `-MT', or use multiple `-MT' options. 4260 4261 For example, `-MT '$(objpfx)foo.o'' might give 4262 4263 $(objpfx)foo.o: foo.c 4264 4265`-MQ TARGET' 4266 Same as `-MT', but it quotes any characters which are special to 4267 Make. `-MQ '$(objpfx)foo.o'' gives 4268 4269 $$(objpfx)foo.o: foo.c 4270 4271 The default target is automatically quoted, as if it were given 4272 with `-MQ'. 4273 4274`-MD' 4275 `-MD' is equivalent to `-M -MF FILE', except that `-E' is not 4276 implied. The driver determines FILE based on whether an `-o' 4277 option is given. If it is, the driver uses its argument but with 4278 a suffix of `.d', otherwise it takes the name of the input file, 4279 removes any directory components and suffix, and applies a `.d' 4280 suffix. 4281 4282 If `-MD' is used in conjunction with `-E', any `-o' switch is 4283 understood to specify the dependency output file (*note -MF: 4284 dashMF.), but if used without `-E', each `-o' is understood to 4285 specify a target object file. 4286 4287 Since `-E' is not implied, `-MD' can be used to generate a 4288 dependency output file as a side-effect of the compilation process. 4289 4290`-MMD' 4291 Like `-MD' except mention only user header files, not system 4292 header files. 4293 4294`-x c' 4295`-x c++' 4296`-x objective-c' 4297`-x assembler-with-cpp' 4298 Specify the source language: C, C++, Objective-C, or assembly. 4299 This has nothing to do with standards conformance or extensions; 4300 it merely selects which base syntax to expect. If you give none 4301 of these options, cpp will deduce the language from the extension 4302 of the source file: `.c', `.cc', `.m', or `.S'. Some other common 4303 extensions for C++ and assembly are also recognized. If cpp does 4304 not recognize the extension, it will treat the file as C; this is 4305 the most generic mode. 4306 4307 _Note:_ Previous versions of cpp accepted a `-lang' option which 4308 selected both the language and the standards conformance level. 4309 This option has been removed, because it conflicts with the `-l' 4310 option. 4311 4312`-std=STANDARD' 4313`-ansi' 4314 Specify the standard to which the code should conform. Currently 4315 CPP knows about C and C++ standards; others may be added in the 4316 future. 4317 4318 STANDARD may be one of: 4319 `c90' 4320 `c89' 4321 `iso9899:1990' 4322 The ISO C standard from 1990. `c90' is the customary 4323 shorthand for this version of the standard. 4324 4325 The `-ansi' option is equivalent to `-std=c90'. 4326 4327 `iso9899:199409' 4328 The 1990 C standard, as amended in 1994. 4329 4330 `iso9899:1999' 4331 `c99' 4332 `iso9899:199x' 4333 `c9x' 4334 The revised ISO C standard, published in December 1999. 4335 Before publication, this was known as C9X. 4336 4337 `iso9899:2011' 4338 `c11' 4339 `c1x' 4340 The revised ISO C standard, published in December 2011. 4341 Before publication, this was known as C1X. 4342 4343 `gnu90' 4344 `gnu89' 4345 The 1990 C standard plus GNU extensions. This is the default. 4346 4347 `gnu99' 4348 `gnu9x' 4349 The 1999 C standard plus GNU extensions. 4350 4351 `gnu11' 4352 `gnu1x' 4353 The 2011 C standard plus GNU extensions. 4354 4355 `c++98' 4356 The 1998 ISO C++ standard plus amendments. 4357 4358 `gnu++98' 4359 The same as `-std=c++98' plus GNU extensions. This is the 4360 default for C++ code. 4361 4362`-I-' 4363 Split the include path. Any directories specified with `-I' 4364 options before `-I-' are searched only for headers requested with 4365 `#include "FILE"'; they are not searched for `#include <FILE>'. 4366 If additional directories are specified with `-I' options after 4367 the `-I-', those directories are searched for all `#include' 4368 directives. 4369 4370 In addition, `-I-' inhibits the use of the directory of the current 4371 file directory as the first search directory for `#include "FILE"'. 4372 *Note Search Path::. This option has been deprecated. 4373 4374`-nostdinc' 4375 Do not search the standard system directories for header files. 4376 Only the directories you have specified with `-I' options (and the 4377 directory of the current file, if appropriate) are searched. 4378 4379`-nostdinc++' 4380 Do not search for header files in the C++-specific standard 4381 directories, but do still search the other standard directories. 4382 (This option is used when building the C++ library.) 4383 4384`-include FILE' 4385 Process FILE as if `#include "file"' appeared as the first line of 4386 the primary source file. However, the first directory searched 4387 for FILE is the preprocessor's working directory _instead of_ the 4388 directory containing the main source file. If not found there, it 4389 is searched for in the remainder of the `#include "..."' search 4390 chain as normal. 4391 4392 If multiple `-include' options are given, the files are included 4393 in the order they appear on the command line. 4394 4395`-imacros FILE' 4396 Exactly like `-include', except that any output produced by 4397 scanning FILE is thrown away. Macros it defines remain defined. 4398 This allows you to acquire all the macros from a header without 4399 also processing its declarations. 4400 4401 All files specified by `-imacros' are processed before all files 4402 specified by `-include'. 4403 4404`-idirafter DIR' 4405 Search DIR for header files, but do it _after_ all directories 4406 specified with `-I' and the standard system directories have been 4407 exhausted. DIR is treated as a system include directory. If DIR 4408 begins with `=', then the `=' will be replaced by the sysroot 4409 prefix; see `--sysroot' and `-isysroot'. 4410 4411`-iprefix PREFIX' 4412 Specify PREFIX as the prefix for subsequent `-iwithprefix' 4413 options. If the prefix represents a directory, you should include 4414 the final `/'. 4415 4416`-iwithprefix DIR' 4417`-iwithprefixbefore DIR' 4418 Append DIR to the prefix specified previously with `-iprefix', and 4419 add the resulting directory to the include search path. 4420 `-iwithprefixbefore' puts it in the same place `-I' would; 4421 `-iwithprefix' puts it where `-idirafter' would. 4422 4423`-isysroot DIR' 4424 This option is like the `--sysroot' option, but applies only to 4425 header files (except for Darwin targets, where it applies to both 4426 header files and libraries). See the `--sysroot' option for more 4427 information. 4428 4429`-imultilib DIR' 4430 Use DIR as a subdirectory of the directory containing 4431 target-specific C++ headers. 4432 4433`-isystem DIR' 4434 Search DIR for header files, after all directories specified by 4435 `-I' but before the standard system directories. Mark it as a 4436 system directory, so that it gets the same special treatment as is 4437 applied to the standard system directories. *Note System 4438 Headers::. If DIR begins with `=', then the `=' will be replaced 4439 by the sysroot prefix; see `--sysroot' and `-isysroot'. 4440 4441`-iquote DIR' 4442 Search DIR only for header files requested with `#include "FILE"'; 4443 they are not searched for `#include <FILE>', before all 4444 directories specified by `-I' and before the standard system 4445 directories. *Note Search Path::. If DIR begins with `=', then 4446 the `=' will be replaced by the sysroot prefix; see `--sysroot' 4447 and `-isysroot'. 4448 4449`-fdirectives-only' 4450 When preprocessing, handle directives, but do not expand macros. 4451 4452 The option's behavior depends on the `-E' and `-fpreprocessed' 4453 options. 4454 4455 With `-E', preprocessing is limited to the handling of directives 4456 such as `#define', `#ifdef', and `#error'. Other preprocessor 4457 operations, such as macro expansion and trigraph conversion are 4458 not performed. In addition, the `-dD' option is implicitly 4459 enabled. 4460 4461 With `-fpreprocessed', predefinition of command line and most 4462 builtin macros is disabled. Macros such as `__LINE__', which are 4463 contextually dependent, are handled normally. This enables 4464 compilation of files previously preprocessed with `-E 4465 -fdirectives-only'. 4466 4467 With both `-E' and `-fpreprocessed', the rules for 4468 `-fpreprocessed' take precedence. This enables full preprocessing 4469 of files previously preprocessed with `-E -fdirectives-only'. 4470 4471`-fdollars-in-identifiers' 4472 Accept `$' in identifiers. *Note Identifier characters::. 4473 4474`-fextended-identifiers' 4475 Accept universal character names in identifiers. This option is 4476 experimental; in a future version of GCC, it will be enabled by 4477 default for C99 and C++. 4478 4479`-fno-canonical-system-headers' 4480 When preprocessing, do not shorten system header paths with 4481 canonicalization. 4482 4483`-fpreprocessed' 4484 Indicate to the preprocessor that the input file has already been 4485 preprocessed. This suppresses things like macro expansion, 4486 trigraph conversion, escaped newline splicing, and processing of 4487 most directives. The preprocessor still recognizes and removes 4488 comments, so that you can pass a file preprocessed with `-C' to 4489 the compiler without problems. In this mode the integrated 4490 preprocessor is little more than a tokenizer for the front ends. 4491 4492 `-fpreprocessed' is implicit if the input file has one of the 4493 extensions `.i', `.ii' or `.mi'. These are the extensions that 4494 GCC uses for preprocessed files created by `-save-temps'. 4495 4496`-ftabstop=WIDTH' 4497 Set the distance between tab stops. This helps the preprocessor 4498 report correct column numbers in warnings or errors, even if tabs 4499 appear on the line. If the value is less than 1 or greater than 4500 100, the option is ignored. The default is 8. 4501 4502`-fdebug-cpp' 4503 This option is only useful for debugging GCC. When used with 4504 `-E', dumps debugging information about location maps. Every 4505 token in the output is preceded by the dump of the map its location 4506 belongs to. The dump of the map holding the location of a token 4507 would be: 4508 {`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} 4509 4510 When used without `-E', this option has no effect. 4511 4512`-ftrack-macro-expansion[=LEVEL]' 4513 Track locations of tokens across macro expansions. This allows the 4514 compiler to emit diagnostic about the current macro expansion stack 4515 when a compilation error occurs in a macro expansion. Using this 4516 option makes the preprocessor and the compiler consume more 4517 memory. The LEVEL parameter can be used to choose the level of 4518 precision of token location tracking thus decreasing the memory 4519 consumption if necessary. Value `0' of LEVEL de-activates this 4520 option just as if no `-ftrack-macro-expansion' was present on the 4521 command line. Value `1' tracks tokens locations in a degraded mode 4522 for the sake of minimal memory overhead. In this mode all tokens 4523 resulting from the expansion of an argument of a function-like 4524 macro have the same location. Value `2' tracks tokens locations 4525 completely. This value is the most memory hungry. When this 4526 option is given no argument, the default parameter value is `2'. 4527 4528 Note that -ftrack-macro-expansion=2 is activated by default. 4529 4530`-fexec-charset=CHARSET' 4531 Set the execution character set, used for string and character 4532 constants. The default is UTF-8. CHARSET can be any encoding 4533 supported by the system's `iconv' library routine. 4534 4535`-fwide-exec-charset=CHARSET' 4536 Set the wide execution character set, used for wide string and 4537 character constants. The default is UTF-32 or UTF-16, whichever 4538 corresponds to the width of `wchar_t'. As with `-fexec-charset', 4539 CHARSET can be any encoding supported by the system's `iconv' 4540 library routine; however, you will have problems with encodings 4541 that do not fit exactly in `wchar_t'. 4542 4543`-finput-charset=CHARSET' 4544 Set the input character set, used for translation from the 4545 character set of the input file to the source character set used 4546 by GCC. If the locale does not specify, or GCC cannot get this 4547 information from the locale, the default is UTF-8. This can be 4548 overridden by either the locale or this command line option. 4549 Currently the command line option takes precedence if there's a 4550 conflict. CHARSET can be any encoding supported by the system's 4551 `iconv' library routine. 4552 4553`-fworking-directory' 4554 Enable generation of linemarkers in the preprocessor output that 4555 will let the compiler know the current working directory at the 4556 time of preprocessing. When this option is enabled, the 4557 preprocessor will emit, after the initial linemarker, a second 4558 linemarker with the current working directory followed by two 4559 slashes. GCC will use this directory, when it's present in the 4560 preprocessed input, as the directory emitted as the current 4561 working directory in some debugging information formats. This 4562 option is implicitly enabled if debugging information is enabled, 4563 but this can be inhibited with the negated form 4564 `-fno-working-directory'. If the `-P' flag is present in the 4565 command line, this option has no effect, since no `#line' 4566 directives are emitted whatsoever. 4567 4568`-fno-show-column' 4569 Do not print column numbers in diagnostics. This may be necessary 4570 if diagnostics are being scanned by a program that does not 4571 understand the column numbers, such as `dejagnu'. 4572 4573`-A PREDICATE=ANSWER' 4574 Make an assertion with the predicate PREDICATE and answer ANSWER. 4575 This form is preferred to the older form `-A PREDICATE(ANSWER)', 4576 which is still supported, because it does not use shell special 4577 characters. *Note Obsolete Features::. 4578 4579`-A -PREDICATE=ANSWER' 4580 Cancel an assertion with the predicate PREDICATE and answer ANSWER. 4581 4582`-dCHARS' 4583 CHARS is a sequence of one or more of the following characters, 4584 and must not be preceded by a space. Other characters are 4585 interpreted by the compiler proper, or reserved for future 4586 versions of GCC, and so are silently ignored. If you specify 4587 characters whose behavior conflicts, the result is undefined. 4588 4589 `M' 4590 Instead of the normal output, generate a list of `#define' 4591 directives for all the macros defined during the execution of 4592 the preprocessor, including predefined macros. This gives 4593 you a way of finding out what is predefined in your version 4594 of the preprocessor. Assuming you have no file `foo.h', the 4595 command 4596 4597 touch foo.h; cpp -dM foo.h 4598 4599 will show all the predefined macros. 4600 4601 If you use `-dM' without the `-E' option, `-dM' is 4602 interpreted as a synonym for `-fdump-rtl-mach'. *Note 4603 Debugging Options: (gcc)Debugging Options. 4604 4605 `D' 4606 Like `M' except in two respects: it does _not_ include the 4607 predefined macros, and it outputs _both_ the `#define' 4608 directives and the result of preprocessing. Both kinds of 4609 output go to the standard output file. 4610 4611 `N' 4612 Like `D', but emit only the macro names, not their expansions. 4613 4614 `I' 4615 Output `#include' directives in addition to the result of 4616 preprocessing. 4617 4618 `U' 4619 Like `D' except that only macros that are expanded, or whose 4620 definedness is tested in preprocessor directives, are output; 4621 the output is delayed until the use or test of the macro; and 4622 `#undef' directives are also output for macros tested but 4623 undefined at the time. 4624 4625`-P' 4626 Inhibit generation of linemarkers in the output from the 4627 preprocessor. This might be useful when running the preprocessor 4628 on something that is not C code, and will be sent to a program 4629 which might be confused by the linemarkers. *Note Preprocessor 4630 Output::. 4631 4632`-C' 4633 Do not discard comments. All comments are passed through to the 4634 output file, except for comments in processed directives, which 4635 are deleted along with the directive. 4636 4637 You should be prepared for side effects when using `-C'; it causes 4638 the preprocessor to treat comments as tokens in their own right. 4639 For example, comments appearing at the start of what would be a 4640 directive line have the effect of turning that line into an 4641 ordinary source line, since the first token on the line is no 4642 longer a `#'. 4643 4644`-CC' 4645 Do not discard comments, including during macro expansion. This is 4646 like `-C', except that comments contained within macros are also 4647 passed through to the output file where the macro is expanded. 4648 4649 In addition to the side-effects of the `-C' option, the `-CC' 4650 option causes all C++-style comments inside a macro to be 4651 converted to C-style comments. This is to prevent later use of 4652 that macro from inadvertently commenting out the remainder of the 4653 source line. 4654 4655 The `-CC' option is generally used to support lint comments. 4656 4657`-traditional-cpp' 4658 Try to imitate the behavior of old-fashioned C preprocessors, as 4659 opposed to ISO C preprocessors. *Note Traditional Mode::. 4660 4661`-trigraphs' 4662 Process trigraph sequences. *Note Initial processing::. 4663 4664`-remap' 4665 Enable special code to work around file systems which only permit 4666 very short file names, such as MS-DOS. 4667 4668`--help' 4669`--target-help' 4670 Print text describing all the command line options instead of 4671 preprocessing anything. 4672 4673`-v' 4674 Verbose mode. Print out GNU CPP's version number at the beginning 4675 of execution, and report the final form of the include path. 4676 4677`-H' 4678 Print the name of each header file used, in addition to other 4679 normal activities. Each name is indented to show how deep in the 4680 `#include' stack it is. Precompiled header files are also 4681 printed, even if they are found to be invalid; an invalid 4682 precompiled header file is printed with `...x' and a valid one 4683 with `...!' . 4684 4685`-version' 4686`--version' 4687 Print out GNU CPP's version number. With one dash, proceed to 4688 preprocess as normal. With two dashes, exit immediately. 4689 4690 4691File: cpp.info, Node: Environment Variables, Next: GNU Free Documentation License, Prev: Invocation, Up: Top 4692 469313 Environment Variables 4694************************ 4695 4696This section describes the environment variables that affect how CPP 4697operates. You can use them to specify directories or prefixes to use 4698when searching for include files, or to control dependency output. 4699 4700 Note that you can also specify places to search using options such as 4701`-I', and control dependency output with options like `-M' (*note 4702Invocation::). These take precedence over environment variables, which 4703in turn take precedence over the configuration of GCC. 4704 4705`CPATH' 4706`C_INCLUDE_PATH' 4707`CPLUS_INCLUDE_PATH' 4708`OBJC_INCLUDE_PATH' 4709 Each variable's value is a list of directories separated by a 4710 special character, much like `PATH', in which to look for header 4711 files. The special character, `PATH_SEPARATOR', is 4712 target-dependent and determined at GCC build time. For Microsoft 4713 Windows-based targets it is a semicolon, and for almost all other 4714 targets it is a colon. 4715 4716 `CPATH' specifies a list of directories to be searched as if 4717 specified with `-I', but after any paths given with `-I' options 4718 on the command line. This environment variable is used regardless 4719 of which language is being preprocessed. 4720 4721 The remaining environment variables apply only when preprocessing 4722 the particular language indicated. Each specifies a list of 4723 directories to be searched as if specified with `-isystem', but 4724 after any paths given with `-isystem' options on the command line. 4725 4726 In all these variables, an empty element instructs the compiler to 4727 search its current working directory. Empty elements can appear 4728 at the beginning or end of a path. For instance, if the value of 4729 `CPATH' is `:/special/include', that has the same effect as 4730 `-I. -I/special/include'. 4731 4732 See also *note Search Path::. 4733 4734`DEPENDENCIES_OUTPUT' 4735 If this variable is set, its value specifies how to output 4736 dependencies for Make based on the non-system header files 4737 processed by the compiler. System header files are ignored in the 4738 dependency output. 4739 4740 The value of `DEPENDENCIES_OUTPUT' can be just a file name, in 4741 which case the Make rules are written to that file, guessing the 4742 target name from the source file name. Or the value can have the 4743 form `FILE TARGET', in which case the rules are written to file 4744 FILE using TARGET as the target name. 4745 4746 In other words, this environment variable is equivalent to 4747 combining the options `-MM' and `-MF' (*note Invocation::), with 4748 an optional `-MT' switch too. 4749 4750`SUNPRO_DEPENDENCIES' 4751 This variable is the same as `DEPENDENCIES_OUTPUT' (see above), 4752 except that system header files are not ignored, so it implies 4753 `-M' rather than `-MM'. However, the dependence on the main input 4754 file is omitted. *Note Invocation::. 4755 4756 4757File: cpp.info, Node: GNU Free Documentation License, Next: Index of Directives, Prev: Environment Variables, Up: Top 4758 4759GNU Free Documentation License 4760****************************** 4761 4762 Version 1.3, 3 November 2008 4763 4764 Copyright (C) 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc. 4765 `http://fsf.org/' 4766 4767 Everyone is permitted to copy and distribute verbatim copies 4768 of this license document, but changing it is not allowed. 4769 4770 0. PREAMBLE 4771 4772 The purpose of this License is to make a manual, textbook, or other 4773 functional and useful document "free" in the sense of freedom: to 4774 assure everyone the effective freedom to copy and redistribute it, 4775 with or without modifying it, either commercially or 4776 noncommercially. Secondarily, this License preserves for the 4777 author and publisher a way to get credit for their work, while not 4778 being considered responsible for modifications made by others. 4779 4780 This License is a kind of "copyleft", which means that derivative 4781 works of the document must themselves be free in the same sense. 4782 It complements the GNU General Public License, which is a copyleft 4783 license designed for free software. 4784 4785 We have designed this License in order to use it for manuals for 4786 free software, because free software needs free documentation: a 4787 free program should come with manuals providing the same freedoms 4788 that the software does. But this License is not limited to 4789 software manuals; it can be used for any textual work, regardless 4790 of subject matter or whether it is published as a printed book. 4791 We recommend this License principally for works whose purpose is 4792 instruction or reference. 4793 4794 1. APPLICABILITY AND DEFINITIONS 4795 4796 This License applies to any manual or other work, in any medium, 4797 that contains a notice placed by the copyright holder saying it 4798 can be distributed under the terms of this License. Such a notice 4799 grants a world-wide, royalty-free license, unlimited in duration, 4800 to use that work under the conditions stated herein. The 4801 "Document", below, refers to any such manual or work. Any member 4802 of the public is a licensee, and is addressed as "you". You 4803 accept the license if you copy, modify or distribute the work in a 4804 way requiring permission under copyright law. 4805 4806 A "Modified Version" of the Document means any work containing the 4807 Document or a portion of it, either copied verbatim, or with 4808 modifications and/or translated into another language. 4809 4810 A "Secondary Section" is a named appendix or a front-matter section 4811 of the Document that deals exclusively with the relationship of the 4812 publishers or authors of the Document to the Document's overall 4813 subject (or to related matters) and contains nothing that could 4814 fall directly within that overall subject. (Thus, if the Document 4815 is in part a textbook of mathematics, a Secondary Section may not 4816 explain any mathematics.) The relationship could be a matter of 4817 historical connection with the subject or with related matters, or 4818 of legal, commercial, philosophical, ethical or political position 4819 regarding them. 4820 4821 The "Invariant Sections" are certain Secondary Sections whose 4822 titles are designated, as being those of Invariant Sections, in 4823 the notice that says that the Document is released under this 4824 License. If a section does not fit the above definition of 4825 Secondary then it is not allowed to be designated as Invariant. 4826 The Document may contain zero Invariant Sections. If the Document 4827 does not identify any Invariant Sections then there are none. 4828 4829 The "Cover Texts" are certain short passages of text that are 4830 listed, as Front-Cover Texts or Back-Cover Texts, in the notice 4831 that says that the Document is released under this License. A 4832 Front-Cover Text may be at most 5 words, and a Back-Cover Text may 4833 be at most 25 words. 4834 4835 A "Transparent" copy of the Document means a machine-readable copy, 4836 represented in a format whose specification is available to the 4837 general public, that is suitable for revising the document 4838 straightforwardly with generic text editors or (for images 4839 composed of pixels) generic paint programs or (for drawings) some 4840 widely available drawing editor, and that is suitable for input to 4841 text formatters or for automatic translation to a variety of 4842 formats suitable for input to text formatters. A copy made in an 4843 otherwise Transparent file format whose markup, or absence of 4844 markup, has been arranged to thwart or discourage subsequent 4845 modification by readers is not Transparent. An image format is 4846 not Transparent if used for any substantial amount of text. A 4847 copy that is not "Transparent" is called "Opaque". 4848 4849 Examples of suitable formats for Transparent copies include plain 4850 ASCII without markup, Texinfo input format, LaTeX input format, 4851 SGML or XML using a publicly available DTD, and 4852 standard-conforming simple HTML, PostScript or PDF designed for 4853 human modification. Examples of transparent image formats include 4854 PNG, XCF and JPG. Opaque formats include proprietary formats that 4855 can be read and edited only by proprietary word processors, SGML or 4856 XML for which the DTD and/or processing tools are not generally 4857 available, and the machine-generated HTML, PostScript or PDF 4858 produced by some word processors for output purposes only. 4859 4860 The "Title Page" means, for a printed book, the title page itself, 4861 plus such following pages as are needed to hold, legibly, the 4862 material this License requires to appear in the title page. For 4863 works in formats which do not have any title page as such, "Title 4864 Page" means the text near the most prominent appearance of the 4865 work's title, preceding the beginning of the body of the text. 4866 4867 The "publisher" means any person or entity that distributes copies 4868 of the Document to the public. 4869 4870 A section "Entitled XYZ" means a named subunit of the Document 4871 whose title either is precisely XYZ or contains XYZ in parentheses 4872 following text that translates XYZ in another language. (Here XYZ 4873 stands for a specific section name mentioned below, such as 4874 "Acknowledgements", "Dedications", "Endorsements", or "History".) 4875 To "Preserve the Title" of such a section when you modify the 4876 Document means that it remains a section "Entitled XYZ" according 4877 to this definition. 4878 4879 The Document may include Warranty Disclaimers next to the notice 4880 which states that this License applies to the Document. These 4881 Warranty Disclaimers are considered to be included by reference in 4882 this License, but only as regards disclaiming warranties: any other 4883 implication that these Warranty Disclaimers may have is void and 4884 has no effect on the meaning of this License. 4885 4886 2. VERBATIM COPYING 4887 4888 You may copy and distribute the Document in any medium, either 4889 commercially or noncommercially, provided that this License, the 4890 copyright notices, and the license notice saying this License 4891 applies to the Document are reproduced in all copies, and that you 4892 add no other conditions whatsoever to those of this License. You 4893 may not use technical measures to obstruct or control the reading 4894 or further copying of the copies you make or distribute. However, 4895 you may accept compensation in exchange for copies. If you 4896 distribute a large enough number of copies you must also follow 4897 the conditions in section 3. 4898 4899 You may also lend copies, under the same conditions stated above, 4900 and you may publicly display copies. 4901 4902 3. COPYING IN QUANTITY 4903 4904 If you publish printed copies (or copies in media that commonly 4905 have printed covers) of the Document, numbering more than 100, and 4906 the Document's license notice requires Cover Texts, you must 4907 enclose the copies in covers that carry, clearly and legibly, all 4908 these Cover Texts: Front-Cover Texts on the front cover, and 4909 Back-Cover Texts on the back cover. Both covers must also clearly 4910 and legibly identify you as the publisher of these copies. The 4911 front cover must present the full title with all words of the 4912 title equally prominent and visible. You may add other material 4913 on the covers in addition. Copying with changes limited to the 4914 covers, as long as they preserve the title of the Document and 4915 satisfy these conditions, can be treated as verbatim copying in 4916 other respects. 4917 4918 If the required texts for either cover are too voluminous to fit 4919 legibly, you should put the first ones listed (as many as fit 4920 reasonably) on the actual cover, and continue the rest onto 4921 adjacent pages. 4922 4923 If you publish or distribute Opaque copies of the Document 4924 numbering more than 100, you must either include a 4925 machine-readable Transparent copy along with each Opaque copy, or 4926 state in or with each Opaque copy a computer-network location from 4927 which the general network-using public has access to download 4928 using public-standard network protocols a complete Transparent 4929 copy of the Document, free of added material. If you use the 4930 latter option, you must take reasonably prudent steps, when you 4931 begin distribution of Opaque copies in quantity, to ensure that 4932 this Transparent copy will remain thus accessible at the stated 4933 location until at least one year after the last time you 4934 distribute an Opaque copy (directly or through your agents or 4935 retailers) of that edition to the public. 4936 4937 It is requested, but not required, that you contact the authors of 4938 the Document well before redistributing any large number of 4939 copies, to give them a chance to provide you with an updated 4940 version of the Document. 4941 4942 4. MODIFICATIONS 4943 4944 You may copy and distribute a Modified Version of the Document 4945 under the conditions of sections 2 and 3 above, provided that you 4946 release the Modified Version under precisely this License, with 4947 the Modified Version filling the role of the Document, thus 4948 licensing distribution and modification of the Modified Version to 4949 whoever possesses a copy of it. In addition, you must do these 4950 things in the Modified Version: 4951 4952 A. Use in the Title Page (and on the covers, if any) a title 4953 distinct from that of the Document, and from those of 4954 previous versions (which should, if there were any, be listed 4955 in the History section of the Document). You may use the 4956 same title as a previous version if the original publisher of 4957 that version gives permission. 4958 4959 B. List on the Title Page, as authors, one or more persons or 4960 entities responsible for authorship of the modifications in 4961 the Modified Version, together with at least five of the 4962 principal authors of the Document (all of its principal 4963 authors, if it has fewer than five), unless they release you 4964 from this requirement. 4965 4966 C. State on the Title page the name of the publisher of the 4967 Modified Version, as the publisher. 4968 4969 D. Preserve all the copyright notices of the Document. 4970 4971 E. Add an appropriate copyright notice for your modifications 4972 adjacent to the other copyright notices. 4973 4974 F. Include, immediately after the copyright notices, a license 4975 notice giving the public permission to use the Modified 4976 Version under the terms of this License, in the form shown in 4977 the Addendum below. 4978 4979 G. Preserve in that license notice the full lists of Invariant 4980 Sections and required Cover Texts given in the Document's 4981 license notice. 4982 4983 H. Include an unaltered copy of this License. 4984 4985 I. Preserve the section Entitled "History", Preserve its Title, 4986 and add to it an item stating at least the title, year, new 4987 authors, and publisher of the Modified Version as given on 4988 the Title Page. If there is no section Entitled "History" in 4989 the Document, create one stating the title, year, authors, 4990 and publisher of the Document as given on its Title Page, 4991 then add an item describing the Modified Version as stated in 4992 the previous sentence. 4993 4994 J. Preserve the network location, if any, given in the Document 4995 for public access to a Transparent copy of the Document, and 4996 likewise the network locations given in the Document for 4997 previous versions it was based on. These may be placed in 4998 the "History" section. You may omit a network location for a 4999 work that was published at least four years before the 5000 Document itself, or if the original publisher of the version 5001 it refers to gives permission. 5002 5003 K. For any section Entitled "Acknowledgements" or "Dedications", 5004 Preserve the Title of the section, and preserve in the 5005 section all the substance and tone of each of the contributor 5006 acknowledgements and/or dedications given therein. 5007 5008 L. Preserve all the Invariant Sections of the Document, 5009 unaltered in their text and in their titles. Section numbers 5010 or the equivalent are not considered part of the section 5011 titles. 5012 5013 M. Delete any section Entitled "Endorsements". Such a section 5014 may not be included in the Modified Version. 5015 5016 N. Do not retitle any existing section to be Entitled 5017 "Endorsements" or to conflict in title with any Invariant 5018 Section. 5019 5020 O. Preserve any Warranty Disclaimers. 5021 5022 If the Modified Version includes new front-matter sections or 5023 appendices that qualify as Secondary Sections and contain no 5024 material copied from the Document, you may at your option 5025 designate some or all of these sections as invariant. To do this, 5026 add their titles to the list of Invariant Sections in the Modified 5027 Version's license notice. These titles must be distinct from any 5028 other section titles. 5029 5030 You may add a section Entitled "Endorsements", provided it contains 5031 nothing but endorsements of your Modified Version by various 5032 parties--for example, statements of peer review or that the text 5033 has been approved by an organization as the authoritative 5034 definition of a standard. 5035 5036 You may add a passage of up to five words as a Front-Cover Text, 5037 and a passage of up to 25 words as a Back-Cover Text, to the end 5038 of the list of Cover Texts in the Modified Version. Only one 5039 passage of Front-Cover Text and one of Back-Cover Text may be 5040 added by (or through arrangements made by) any one entity. If the 5041 Document already includes a cover text for the same cover, 5042 previously added by you or by arrangement made by the same entity 5043 you are acting on behalf of, you may not add another; but you may 5044 replace the old one, on explicit permission from the previous 5045 publisher that added the old one. 5046 5047 The author(s) and publisher(s) of the Document do not by this 5048 License give permission to use their names for publicity for or to 5049 assert or imply endorsement of any Modified Version. 5050 5051 5. COMBINING DOCUMENTS 5052 5053 You may combine the Document with other documents released under 5054 this License, under the terms defined in section 4 above for 5055 modified versions, provided that you include in the combination 5056 all of the Invariant Sections of all of the original documents, 5057 unmodified, and list them all as Invariant Sections of your 5058 combined work in its license notice, and that you preserve all 5059 their Warranty Disclaimers. 5060 5061 The combined work need only contain one copy of this License, and 5062 multiple identical Invariant Sections may be replaced with a single 5063 copy. If there are multiple Invariant Sections with the same name 5064 but different contents, make the title of each such section unique 5065 by adding at the end of it, in parentheses, the name of the 5066 original author or publisher of that section if known, or else a 5067 unique number. Make the same adjustment to the section titles in 5068 the list of Invariant Sections in the license notice of the 5069 combined work. 5070 5071 In the combination, you must combine any sections Entitled 5072 "History" in the various original documents, forming one section 5073 Entitled "History"; likewise combine any sections Entitled 5074 "Acknowledgements", and any sections Entitled "Dedications". You 5075 must delete all sections Entitled "Endorsements." 5076 5077 6. COLLECTIONS OF DOCUMENTS 5078 5079 You may make a collection consisting of the Document and other 5080 documents released under this License, and replace the individual 5081 copies of this License in the various documents with a single copy 5082 that is included in the collection, provided that you follow the 5083 rules of this License for verbatim copying of each of the 5084 documents in all other respects. 5085 5086 You may extract a single document from such a collection, and 5087 distribute it individually under this License, provided you insert 5088 a copy of this License into the extracted document, and follow 5089 this License in all other respects regarding verbatim copying of 5090 that document. 5091 5092 7. AGGREGATION WITH INDEPENDENT WORKS 5093 5094 A compilation of the Document or its derivatives with other 5095 separate and independent documents or works, in or on a volume of 5096 a storage or distribution medium, is called an "aggregate" if the 5097 copyright resulting from the compilation is not used to limit the 5098 legal rights of the compilation's users beyond what the individual 5099 works permit. When the Document is included in an aggregate, this 5100 License does not apply to the other works in the aggregate which 5101 are not themselves derivative works of the Document. 5102 5103 If the Cover Text requirement of section 3 is applicable to these 5104 copies of the Document, then if the Document is less than one half 5105 of the entire aggregate, the Document's Cover Texts may be placed 5106 on covers that bracket the Document within the aggregate, or the 5107 electronic equivalent of covers if the Document is in electronic 5108 form. Otherwise they must appear on printed covers that bracket 5109 the whole aggregate. 5110 5111 8. TRANSLATION 5112 5113 Translation is considered a kind of modification, so you may 5114 distribute translations of the Document under the terms of section 5115 4. Replacing Invariant Sections with translations requires special 5116 permission from their copyright holders, but you may include 5117 translations of some or all Invariant Sections in addition to the 5118 original versions of these Invariant Sections. You may include a 5119 translation of this License, and all the license notices in the 5120 Document, and any Warranty Disclaimers, provided that you also 5121 include the original English version of this License and the 5122 original versions of those notices and disclaimers. In case of a 5123 disagreement between the translation and the original version of 5124 this License or a notice or disclaimer, the original version will 5125 prevail. 5126 5127 If a section in the Document is Entitled "Acknowledgements", 5128 "Dedications", or "History", the requirement (section 4) to 5129 Preserve its Title (section 1) will typically require changing the 5130 actual title. 5131 5132 9. TERMINATION 5133 5134 You may not copy, modify, sublicense, or distribute the Document 5135 except as expressly provided under this License. Any attempt 5136 otherwise to copy, modify, sublicense, or distribute it is void, 5137 and will automatically terminate your rights under this License. 5138 5139 However, if you cease all violation of this License, then your 5140 license from a particular copyright holder is reinstated (a) 5141 provisionally, unless and until the copyright holder explicitly 5142 and finally terminates your license, and (b) permanently, if the 5143 copyright holder fails to notify you of the violation by some 5144 reasonable means prior to 60 days after the cessation. 5145 5146 Moreover, your license from a particular copyright holder is 5147 reinstated permanently if the copyright holder notifies you of the 5148 violation by some reasonable means, this is the first time you have 5149 received notice of violation of this License (for any work) from 5150 that copyright holder, and you cure the violation prior to 30 days 5151 after your receipt of the notice. 5152 5153 Termination of your rights under this section does not terminate 5154 the licenses of parties who have received copies or rights from 5155 you under this License. If your rights have been terminated and 5156 not permanently reinstated, receipt of a copy of some or all of 5157 the same material does not give you any rights to use it. 5158 5159 10. FUTURE REVISIONS OF THIS LICENSE 5160 5161 The Free Software Foundation may publish new, revised versions of 5162 the GNU Free Documentation License from time to time. Such new 5163 versions will be similar in spirit to the present version, but may 5164 differ in detail to address new problems or concerns. See 5165 `http://www.gnu.org/copyleft/'. 5166 5167 Each version of the License is given a distinguishing version 5168 number. If the Document specifies that a particular numbered 5169 version of this License "or any later version" applies to it, you 5170 have the option of following the terms and conditions either of 5171 that specified version or of any later version that has been 5172 published (not as a draft) by the Free Software Foundation. If 5173 the Document does not specify a version number of this License, 5174 you may choose any version ever published (not as a draft) by the 5175 Free Software Foundation. If the Document specifies that a proxy 5176 can decide which future versions of this License can be used, that 5177 proxy's public statement of acceptance of a version permanently 5178 authorizes you to choose that version for the Document. 5179 5180 11. RELICENSING 5181 5182 "Massive Multiauthor Collaboration Site" (or "MMC Site") means any 5183 World Wide Web server that publishes copyrightable works and also 5184 provides prominent facilities for anybody to edit those works. A 5185 public wiki that anybody can edit is an example of such a server. 5186 A "Massive Multiauthor Collaboration" (or "MMC") contained in the 5187 site means any set of copyrightable works thus published on the MMC 5188 site. 5189 5190 "CC-BY-SA" means the Creative Commons Attribution-Share Alike 3.0 5191 license published by Creative Commons Corporation, a not-for-profit 5192 corporation with a principal place of business in San Francisco, 5193 California, as well as future copyleft versions of that license 5194 published by that same organization. 5195 5196 "Incorporate" means to publish or republish a Document, in whole or 5197 in part, as part of another Document. 5198 5199 An MMC is "eligible for relicensing" if it is licensed under this 5200 License, and if all works that were first published under this 5201 License somewhere other than this MMC, and subsequently 5202 incorporated in whole or in part into the MMC, (1) had no cover 5203 texts or invariant sections, and (2) were thus incorporated prior 5204 to November 1, 2008. 5205 5206 The operator of an MMC Site may republish an MMC contained in the 5207 site under CC-BY-SA on the same site at any time before August 1, 5208 2009, provided the MMC is eligible for relicensing. 5209 5210 5211ADDENDUM: How to use this License for your documents 5212==================================================== 5213 5214To use this License in a document you have written, include a copy of 5215the License in the document and put the following copyright and license 5216notices just after the title page: 5217 5218 Copyright (C) YEAR YOUR NAME. 5219 Permission is granted to copy, distribute and/or modify this document 5220 under the terms of the GNU Free Documentation License, Version 1.3 5221 or any later version published by the Free Software Foundation; 5222 with no Invariant Sections, no Front-Cover Texts, and no Back-Cover 5223 Texts. A copy of the license is included in the section entitled ``GNU 5224 Free Documentation License''. 5225 5226 If you have Invariant Sections, Front-Cover Texts and Back-Cover 5227Texts, replace the "with...Texts." line with this: 5228 5229 with the Invariant Sections being LIST THEIR TITLES, with 5230 the Front-Cover Texts being LIST, and with the Back-Cover Texts 5231 being LIST. 5232 5233 If you have Invariant Sections without Cover Texts, or some other 5234combination of the three, merge those two alternatives to suit the 5235situation. 5236 5237 If your document contains nontrivial examples of program code, we 5238recommend releasing these examples in parallel under your choice of 5239free software license, such as the GNU General Public License, to 5240permit their use in free software. 5241 5242 5243File: cpp.info, Node: Index of Directives, Next: Option Index, Prev: GNU Free Documentation License, Up: Top 5244 5245Index of Directives 5246******************* 5247 5248[index] 5249* Menu: 5250 5251* #assert: Obsolete Features. (line 48) 5252* #define: Object-like Macros. (line 11) 5253* #elif: Elif. (line 6) 5254* #else: Else. (line 6) 5255* #endif: Ifdef. (line 6) 5256* #error: Diagnostics. (line 6) 5257* #ident: Other Directives. (line 6) 5258* #if: Conditional Syntax. (line 6) 5259* #ifdef: Ifdef. (line 6) 5260* #ifndef: Ifdef. (line 40) 5261* #import: Alternatives to Wrapper #ifndef. 5262 (line 11) 5263* #include: Include Syntax. (line 6) 5264* #include_next: Wrapper Headers. (line 6) 5265* #line: Line Control. (line 20) 5266* #pragma GCC dependency: Pragmas. (line 55) 5267* #pragma GCC error: Pragmas. (line 100) 5268* #pragma GCC poison: Pragmas. (line 67) 5269* #pragma GCC system_header <1>: Pragmas. (line 94) 5270* #pragma GCC system_header: System Headers. (line 31) 5271* #pragma GCC warning: Pragmas. (line 99) 5272* #sccs: Other Directives. (line 6) 5273* #unassert: Obsolete Features. (line 59) 5274* #undef: Undefining and Redefining Macros. 5275 (line 6) 5276* #warning: Diagnostics. (line 27) 5277 5278 5279File: cpp.info, Node: Option Index, Next: Concept Index, Prev: Index of Directives, Up: Top 5280 5281Option Index 5282************ 5283 5284CPP's command line options and environment variables are indexed here 5285without any initial `-' or `--'. 5286 5287[index] 5288* Menu: 5289 5290* A: Invocation. (line 568) 5291* ansi: Invocation. (line 308) 5292* C: Invocation. (line 627) 5293* C_INCLUDE_PATH: Environment Variables. 5294 (line 16) 5295* CPATH: Environment Variables. 5296 (line 15) 5297* CPLUS_INCLUDE_PATH: Environment Variables. 5298 (line 17) 5299* D: Invocation. (line 39) 5300* dD: Invocation. (line 600) 5301* DEPENDENCIES_OUTPUT: Environment Variables. 5302 (line 44) 5303* dI: Invocation. (line 609) 5304* dM: Invocation. (line 584) 5305* dN: Invocation. (line 606) 5306* dU: Invocation. (line 613) 5307* fdebug-cpp: Invocation. (line 497) 5308* fdirectives-only: Invocation. (line 444) 5309* fdollars-in-identifiers: Invocation. (line 466) 5310* fexec-charset: Invocation. (line 525) 5311* fextended-identifiers: Invocation. (line 469) 5312* finput-charset: Invocation. (line 538) 5313* fno-canonical-system-headers: Invocation. (line 474) 5314* fno-show-column: Invocation. (line 563) 5315* fno-working-directory: Invocation. (line 548) 5316* fpreprocessed: Invocation. (line 478) 5317* ftabstop: Invocation. (line 491) 5318* ftrack-macro-expansion: Invocation. (line 507) 5319* fwide-exec-charset: Invocation. (line 530) 5320* fworking-directory: Invocation. (line 548) 5321* H: Invocation. (line 672) 5322* help: Invocation. (line 664) 5323* I: Invocation. (line 71) 5324* I-: Invocation. (line 357) 5325* idirafter: Invocation. (line 399) 5326* imacros: Invocation. (line 390) 5327* imultilib: Invocation. (line 424) 5328* include: Invocation. (line 379) 5329* iprefix: Invocation. (line 406) 5330* iquote: Invocation. (line 436) 5331* isysroot: Invocation. (line 418) 5332* isystem: Invocation. (line 428) 5333* iwithprefix: Invocation. (line 412) 5334* iwithprefixbefore: Invocation. (line 412) 5335* M: Invocation. (line 180) 5336* MD: Invocation. (line 269) 5337* MF: Invocation. (line 215) 5338* MG: Invocation. (line 224) 5339* MM: Invocation. (line 205) 5340* MMD: Invocation. (line 285) 5341* MP: Invocation. (line 234) 5342* MQ: Invocation. (line 260) 5343* MT: Invocation. (line 246) 5344* nostdinc: Invocation. (line 369) 5345* nostdinc++: Invocation. (line 374) 5346* o: Invocation. (line 82) 5347* OBJC_INCLUDE_PATH: Environment Variables. 5348 (line 18) 5349* P: Invocation. (line 620) 5350* pedantic: Invocation. (line 170) 5351* pedantic-errors: Invocation. (line 175) 5352* remap: Invocation. (line 659) 5353* std=: Invocation. (line 308) 5354* SUNPRO_DEPENDENCIES: Environment Variables. 5355 (line 60) 5356* target-help: Invocation. (line 664) 5357* traditional-cpp: Invocation. (line 652) 5358* trigraphs: Invocation. (line 656) 5359* U: Invocation. (line 62) 5360* undef: Invocation. (line 66) 5361* v: Invocation. (line 668) 5362* version: Invocation. (line 681) 5363* w: Invocation. (line 166) 5364* Wall: Invocation. (line 88) 5365* Wcomment: Invocation. (line 96) 5366* Wcomments: Invocation. (line 96) 5367* Wendif-labels: Invocation. (line 143) 5368* Werror: Invocation. (line 156) 5369* Wsystem-headers: Invocation. (line 160) 5370* Wtraditional: Invocation. (line 113) 5371* Wtrigraphs: Invocation. (line 101) 5372* Wundef: Invocation. (line 119) 5373* Wunused-macros: Invocation. (line 124) 5374* x: Invocation. (line 292) 5375 5376 5377File: cpp.info, Node: Concept Index, Prev: Option Index, Up: Top 5378 5379Concept Index 5380************* 5381 5382[index] 5383* Menu: 5384 5385* # operator: Stringification. (line 6) 5386* ## operator: Concatenation. (line 6) 5387* _Pragma: Pragmas. (line 25) 5388* alternative tokens: Tokenization. (line 106) 5389* arguments: Macro Arguments. (line 6) 5390* arguments in macro definitions: Macro Arguments. (line 6) 5391* assertions: Obsolete Features. (line 13) 5392* assertions, canceling: Obsolete Features. (line 59) 5393* backslash-newline: Initial processing. (line 61) 5394* block comments: Initial processing. (line 77) 5395* C++ named operators: C++ Named Operators. (line 6) 5396* character constants: Tokenization. (line 85) 5397* character set, execution: Invocation. (line 525) 5398* character set, input: Invocation. (line 538) 5399* character set, wide execution: Invocation. (line 530) 5400* command line: Invocation. (line 6) 5401* commenting out code: Deleted Code. (line 6) 5402* comments: Initial processing. (line 77) 5403* common predefined macros: Common Predefined Macros. 5404 (line 6) 5405* computed includes: Computed Includes. (line 6) 5406* concatenation: Concatenation. (line 6) 5407* conditional group: Ifdef. (line 14) 5408* conditionals: Conditionals. (line 6) 5409* continued lines: Initial processing. (line 61) 5410* controlling macro: Once-Only Headers. (line 35) 5411* defined: Defined. (line 6) 5412* dependencies for make as output: Environment Variables. 5413 (line 45) 5414* dependencies, make: Invocation. (line 180) 5415* diagnostic: Diagnostics. (line 6) 5416* differences from previous versions: Differences from previous versions. 5417 (line 6) 5418* digraphs: Tokenization. (line 106) 5419* directive line: The preprocessing language. 5420 (line 6) 5421* directive name: The preprocessing language. 5422 (line 6) 5423* directives: The preprocessing language. 5424 (line 6) 5425* empty macro arguments: Macro Arguments. (line 66) 5426* environment variables: Environment Variables. 5427 (line 6) 5428* expansion of arguments: Argument Prescan. (line 6) 5429* FDL, GNU Free Documentation License: GNU Free Documentation License. 5430 (line 6) 5431* function-like macros: Function-like Macros. 5432 (line 6) 5433* grouping options: Invocation. (line 34) 5434* guard macro: Once-Only Headers. (line 35) 5435* header file: Header Files. (line 6) 5436* header file names: Tokenization. (line 85) 5437* identifiers: Tokenization. (line 34) 5438* implementation limits: Implementation limits. 5439 (line 6) 5440* implementation-defined behavior: Implementation-defined behavior. 5441 (line 6) 5442* including just once: Once-Only Headers. (line 6) 5443* invocation: Invocation. (line 6) 5444* iso646.h: C++ Named Operators. (line 6) 5445* line comments: Initial processing. (line 77) 5446* line control: Line Control. (line 6) 5447* line endings: Initial processing. (line 14) 5448* linemarkers: Preprocessor Output. (line 28) 5449* macro argument expansion: Argument Prescan. (line 6) 5450* macro arguments and directives: Directives Within Macro Arguments. 5451 (line 6) 5452* macros in include: Computed Includes. (line 6) 5453* macros with arguments: Macro Arguments. (line 6) 5454* macros with variable arguments: Variadic Macros. (line 6) 5455* make: Invocation. (line 180) 5456* manifest constants: Object-like Macros. (line 6) 5457* named operators: C++ Named Operators. (line 6) 5458* newlines in macro arguments: Newlines in Arguments. 5459 (line 6) 5460* null directive: Other Directives. (line 15) 5461* numbers: Tokenization. (line 61) 5462* object-like macro: Object-like Macros. (line 6) 5463* options: Invocation. (line 38) 5464* options, grouping: Invocation. (line 34) 5465* other tokens: Tokenization. (line 120) 5466* output format: Preprocessor Output. (line 12) 5467* overriding a header file: Wrapper Headers. (line 6) 5468* parentheses in macro bodies: Operator Precedence Problems. 5469 (line 6) 5470* pitfalls of macros: Macro Pitfalls. (line 6) 5471* predefined macros: Predefined Macros. (line 6) 5472* predefined macros, system-specific: System-specific Predefined Macros. 5473 (line 6) 5474* predicates: Obsolete Features. (line 26) 5475* preprocessing directives: The preprocessing language. 5476 (line 6) 5477* preprocessing numbers: Tokenization. (line 61) 5478* preprocessing tokens: Tokenization. (line 6) 5479* prescan of macro arguments: Argument Prescan. (line 6) 5480* problems with macros: Macro Pitfalls. (line 6) 5481* punctuators: Tokenization. (line 106) 5482* redefining macros: Undefining and Redefining Macros. 5483 (line 6) 5484* repeated inclusion: Once-Only Headers. (line 6) 5485* reporting errors: Diagnostics. (line 6) 5486* reporting warnings: Diagnostics. (line 6) 5487* reserved namespace: System-specific Predefined Macros. 5488 (line 6) 5489* self-reference: Self-Referential Macros. 5490 (line 6) 5491* semicolons (after macro calls): Swallowing the Semicolon. 5492 (line 6) 5493* side effects (in macro arguments): Duplication of Side Effects. 5494 (line 6) 5495* standard predefined macros.: Standard Predefined Macros. 5496 (line 6) 5497* string constants: Tokenization. (line 85) 5498* string literals: Tokenization. (line 85) 5499* stringification: Stringification. (line 6) 5500* symbolic constants: Object-like Macros. (line 6) 5501* system header files <1>: System Headers. (line 6) 5502* system header files: Header Files. (line 13) 5503* system-specific predefined macros: System-specific Predefined Macros. 5504 (line 6) 5505* testing predicates: Obsolete Features. (line 37) 5506* token concatenation: Concatenation. (line 6) 5507* token pasting: Concatenation. (line 6) 5508* tokens: Tokenization. (line 6) 5509* trigraphs: Initial processing. (line 32) 5510* undefining macros: Undefining and Redefining Macros. 5511 (line 6) 5512* unsafe macros: Duplication of Side Effects. 5513 (line 6) 5514* variable number of arguments: Variadic Macros. (line 6) 5515* variadic macros: Variadic Macros. (line 6) 5516* wrapper #ifndef: Once-Only Headers. (line 6) 5517* wrapper headers: Wrapper Headers. (line 6) 5518 5519 5520 5521Tag Table: 5522Node: Top1010 5523Node: Overview3615 5524Node: Character sets6448 5525Ref: Character sets-Footnote-18631 5526Node: Initial processing8812 5527Ref: trigraphs10371 5528Node: Tokenization14573 5529Ref: Tokenization-Footnote-121709 5530Node: The preprocessing language21820 5531Node: Header Files24698 5532Node: Include Syntax26614 5533Node: Include Operation28251 5534Node: Search Path30099 5535Node: Once-Only Headers33300 5536Node: Alternatives to Wrapper #ifndef34959 5537Node: Computed Includes36702 5538Node: Wrapper Headers39860 5539Node: System Headers42286 5540Node: Macros44336 5541Node: Object-like Macros45477 5542Node: Function-like Macros49067 5543Node: Macro Arguments50683 5544Node: Stringification54828 5545Node: Concatenation58034 5546Node: Variadic Macros61142 5547Node: Predefined Macros65929 5548Node: Standard Predefined Macros66517 5549Node: Common Predefined Macros72454 5550Node: System-specific Predefined Macros90077 5551Node: C++ Named Operators92100 5552Node: Undefining and Redefining Macros93064 5553Node: Directives Within Macro Arguments95168 5554Node: Macro Pitfalls96716 5555Node: Misnesting97249 5556Node: Operator Precedence Problems98361 5557Node: Swallowing the Semicolon100227 5558Node: Duplication of Side Effects102250 5559Node: Self-Referential Macros104433 5560Node: Argument Prescan106842 5561Node: Newlines in Arguments110596 5562Node: Conditionals111547 5563Node: Conditional Uses113377 5564Node: Conditional Syntax114735 5565Node: Ifdef115055 5566Node: If118216 5567Node: Defined120520 5568Node: Else121803 5569Node: Elif122373 5570Node: Deleted Code123662 5571Node: Diagnostics124909 5572Node: Line Control126456 5573Node: Pragmas130260 5574Node: Other Directives135016 5575Node: Preprocessor Output136066 5576Node: Traditional Mode139267 5577Node: Traditional lexical analysis140325 5578Node: Traditional macros142828 5579Node: Traditional miscellany146630 5580Node: Traditional warnings147627 5581Node: Implementation Details149824 5582Node: Implementation-defined behavior150445 5583Ref: Identifier characters151197 5584Node: Implementation limits154275 5585Node: Obsolete Features156949 5586Node: Differences from previous versions159837 5587Node: Invocation164045 5588Ref: Wtrigraphs168497 5589Ref: dashMF173272 5590Ref: fdollars-in-identifiers183003 5591Node: Environment Variables192872 5592Node: GNU Free Documentation License195838 5593Node: Index of Directives221002 5594Node: Option Index223082 5595Node: Concept Index229485 5596 5597End Tag Table 5598