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