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