cpp - The C Preprocessor For gcc version 4.8.0(GCC Richard...

Info icon This preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
The C Preprocessor For gcc version 4.8.0 (GCC) Richard M. Stallman, Zachary Weinberg
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Copyright c 1987-2013 Free Software Foundation, Inc. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation. A copy of the license is included in the section entitled “GNU Free Documentation License”. This manual contains no Invariant Sections. The Front-Cover Texts are (a) (see below), and the Back-Cover Texts are (b) (see below). (a) The FSF’s Front-Cover Text is: A GNU Manual (b) The FSF’s Back-Cover Text is: You have freedom to copy and modify this GNU Manual, like GNU software. Copies published by the Free Software Foundation raise funds for GNU development.
Image of page 2
i Table of Contents 1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.1 Character sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.2 Initial processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 1.3 Tokenization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 1.4 The preprocessing language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 2 Header Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 2.1 Include Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 2.2 Include Operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 2.3 Search Path . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 2.4 Once-Only Headers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 2.5 Alternatives to Wrapper #ifndef . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 2.6 Computed Includes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 2.7 Wrapper Headers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 2.8 System Headers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 3 Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 3.1 Object-like Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 3.2 Function-like Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 3.3 Macro Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 3.4 Stringification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 3.5 Concatenation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 3.6 Variadic Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 3.7 Predefined Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 3.7.1 Standard Predefined Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 3.7.2 Common Predefined Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 3.7.3 System-specific Predefined Macros . . . . . . . . . . . . . . . . . . . . . . . . 31 3.7.4 C++ Named Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 3.8 Undefining and Redefining Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 3.9 Directives Within Macro Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 3.10 Macro Pitfalls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 3.10.1 Misnesting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 3.10.2 Operator Precedence Problems . . . . . . . . . . . . . . . . . . . . . . . . . . 34 3.10.3 Swallowing the Semicolon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 3.10.4 Duplication of Side Effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 3.10.5 Self-Referential Macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 3.10.6 Argument Prescan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 3.10.7 Newlines in Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
ii 4 Conditionals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 4.1 Conditional Uses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 4.2 Conditional Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 4.2.1 Ifdef . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 4.2.2 If . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 4.2.3 Defined . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 4.2.4 Else . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 4.2.5 Elif . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 4.3 Deleted Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 5 Diagnostics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 6 Line Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 7 Pragmas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 8 Other Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 9 Preprocessor Output . . . . . . . . . . . . . . . . . . . . . . . . . . 47 10 Traditional Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 10.1 Traditional lexical analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 10.2 Traditional macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 10.3 Traditional miscellany . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 10.4 Traditional warnings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 11 Implementation Details . . . . . . . . . . . . . . . . . . . . . . 51 11.1 Implementation-defined behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 11.2 Implementation limits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 11.3 Obsolete Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 11.3.1 Assertions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 11.4 Differences from previous versions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 12 Invocation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 13 Environment Variables . . . . . . . . . . . . . . . . . . . . . . 66 GNU Free Documentation License . . . . . . . . . . . . . . . 68 ADDENDUM: How to use this License for your documents . . . . . . . . . 75 Index of Directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 Option Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 Concept Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
Image of page 4
Chapter 1: Overview 1 1 Overview The C preprocessor, often known as cpp , is a macro processor that is used automatically by the C compiler to transform your program before compilation. It is called a macro processor because it allows you to define macros , which are brief abbreviations for longer constructs. The C preprocessor is intended to be used only with C, C ++ , and Objective-C source code. In the past, it has been abused as a general text processor. It will choke on input which does not obey C’s lexical rules. For example, apostrophes will be interpreted as the beginning of character constants, and cause errors. Also, you cannot rely on it preserving
Image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern