⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cpp.texi

📁 理解和实践操作系统的一本好书
💻 TEXI
📖 第 1 页 / 共 5 页
字号:
\input texinfo@setfilename cpp.info@settitle The C Preprocessor@setchapternewpage off@c @smallbook@c @cropmarks@c @finalout@include gcc-common.texi@copying@c man begin COPYRIGHTCopyright @copyright{} 1987, 1989, 1991, 1992, 1993, 1994, 1995, 1996,1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007Free Software Foundation, Inc.Permission is granted to copy, distribute and/or modify this documentunder the terms of the GNU Free Documentation License, Version 1.1 orany later version published by the Free Software Foundation.  A copy ofthe license is included in the@c man endsection entitled ``GNU Free Documentation License''.@ignore@c man begin COPYRIGHTman page gfdl(7).@c man end@end ignore@c man begin COPYRIGHTThis 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.@c man end@end copying@c Create a separate index for command line options.@defcodeindex op@syncodeindex vr op@c Used in cppopts.texi and cppenv.texi.@set cppmanual@ifinfo@dircategory Software development@direntry* Cpp: (cpp).		       The GNU C preprocessor.@end direntry@end ifinfo@titlepage@title The C Preprocessor@versionsubtitle@author Richard M. Stallman, Zachary Weinberg@page@c There is a fill at the bottom of the page, so we need a filll to@c override it.@vskip 0pt plus 1filll@insertcopying@end titlepage@contents@page@ifnottex@node Top@topThe C preprocessor implements the macro language used to transform C,C++, and Objective-C programs before they are compiled.  It can also beuseful on its own.@menu* Overview::* Header Files::* Macros::* Conditionals::* Diagnostics::* Line Control::* Pragmas::* Other Directives::* Preprocessor Output::* Traditional Mode::* Implementation Details::* Invocation::* Environment Variables::* GNU Free Documentation License::* Index of Directives::* Option Index::* Concept Index::@detailmenu --- The Detailed Node Listing ---Overview* Character sets::* Initial processing::* Tokenization::* The preprocessing language::Header Files* Include Syntax::* Include Operation::* Search Path::* Once-Only Headers::* Computed Includes::* Wrapper Headers::* System Headers::Macros* Object-like Macros::* Function-like Macros::* Macro Arguments::* Stringification::* Concatenation::* Variadic Macros::* Predefined Macros::* Undefining and Redefining Macros::* Directives Within Macro Arguments::* Macro Pitfalls::Predefined Macros* Standard Predefined Macros::* Common Predefined Macros::* System-specific Predefined Macros::* C++ Named Operators::Macro Pitfalls* Misnesting::* Operator Precedence Problems::* Swallowing the Semicolon::* Duplication of Side Effects::* Self-Referential Macros::* Argument Prescan::* Newlines in Arguments::Conditionals* Conditional Uses::* Conditional Syntax::* Deleted Code::Conditional Syntax* Ifdef::* If::* Defined::* Else::* Elif::Implementation Details* Implementation-defined behavior::* Implementation limits::* Obsolete Features::* Differences from previous versions::Obsolete Features* Assertions::* Obsolete once-only headers::@end detailmenu@end menu@insertcopying@end ifnottex@node Overview@chapter Overview@c man begin DESCRIPTIONThe C preprocessor, often known as @dfn{cpp}, is a @dfn{macro processor}that is used automatically by the C compiler to transform your programbefore compilation.  It is called a macro processor because it allowsyou to define @dfn{macros}, which are brief abbreviations for longerconstructs.The C preprocessor is intended to be used only with C, C++, andObjective-C source code.  In the past, it has been abused as a generaltext processor.  It will choke on input which does not obey C's lexicalrules.  For example, apostrophes will be interpreted as the beginning ofcharacter constants, and cause errors.  Also, you cannot rely on itpreserving characteristics of the input which are not significant toC-family languages.  If a Makefile is preprocessed, all the hard tabswill be removed, and the Makefile will not work.Having said that, you can often get away with using cpp on things whichare not C@.  Other Algol-ish programming languages are often safe(Pascal, Ada, etc.) So is assembly, with caution.  @option{-traditional-cpp}mode preserves more white space, and is otherwise more permissive.  Manyof the problems can be avoided by writing C or C++ style commentsinstead of native language comments, and keeping macros simple.Wherever possible, you should use a preprocessor geared to the languageyou are writing in.  Modern versions of the GNU assembler have macrofacilities.  Most high level programming languages have their ownconditional compilation and inclusion mechanism.  If all else fails,try a true general text processor, such as GNU M4.C preprocessors vary in some details.  This manual discusses the GNU Cpreprocessor, which provides a small superset of the features of ISOStandard C@.  In its default mode, the GNU C preprocessor does not do afew things required by the standard.  These are features which arerarely, if ever, used, and may cause surprising changes to the meaningof a program which does not expect them.  To get strict ISO Standard C,you should use the @option{-std=c89} or @option{-std=c99} options, dependingon which version of the standard you want.  To get all the mandatorydiagnostics, you must also use @option{-pedantic}.  @xref{Invocation}.This manual describes the behavior of the ISO preprocessor.  Tominimize gratuitous differences, where the ISO preprocessor'sbehavior does not conflict with traditional semantics, thetraditional preprocessor should behave the same way.  The variousdifferences that do exist are detailed in the section @ref{TraditionalMode}.For clarity, unless noted otherwise, references to @samp{CPP} in thismanual refer to GNU CPP@.@c man end@menu* Character sets::* Initial processing::* Tokenization::* The preprocessing language::@end menu@node Character sets@section Character setsSource code character set processing in C and related languages israther complicated.  The C standard discusses two character sets, butthere are really at least four.The files input to CPP might be in any character set at all.  CPP'svery first action, before it even looks for line boundaries, is toconvert the file into the character set it uses for internalprocessing.  That set is what the C standard calls the @dfn{source}character set.  It must be isomorphic with ISO 10646, also known asUnicode.  CPP uses the UTF-8 encoding of Unicode.The character sets of the input files are specified using the@option{-finput-charset=} option.All preprocessing work (the subject of the rest of this manual) iscarried out in the source character set.  If you request textualoutput from the preprocessor with the @option{-E} option, it will bein UTF-8.After preprocessing is complete, string and character constants areconverted again, into the @dfn{execution} character set.  Thischaracter set is under control of the user; the default is UTF-8,matching the source character set.  Wide string and characterconstants have their own character set, which is not called outspecifically in the standard.  Again, it is under control of the user.The default is UTF-16 or UTF-32, whichever fits in the target's@code{wchar_t} type, in the target machine's byteorder.@footnote{UTF-16 does not meet the requirements of the Cstandard for a wide character set, but the choice of 16-bit@code{wchar_t} is enshrined in some system ABIs so we cannot fixthis.}  Octal and hexadecimal escape sequences do not undergoconversion; @t{'\x12'} has the value 0x12 regardless of the currentlyselected execution character set.  All other escapes are replaced bythe character in the source character set that they represent, thenconverted to the execution character set, just like unescapedcharacters.Unless the experimental @option{-fextended-identifiers} option is used,GCC does not permit the use of characters outside the ASCII range, nor@samp{\u} and @samp{\U} escapes, in identifiers.  Even with thatoption, characters outside the ASCII range can only be specified withthe @samp{\u} and @samp{\U} escapes, not used directly in identifiers.@node Initial processing@section Initial processingThe preprocessor performs a series of textual transformations on itsinput.  These happen before all other processing.  Conceptually, theyhappen in a rigid order, and the entire file is run through eachtransformation before the next one begins.  CPP actually does themall at once, for performance reasons.  These transformations correspondroughly to the first three ``phases of translation'' described in the Cstandard.@enumerate@item@cindex line endingsThe input file is read into memory and broken into lines.Different systems use different conventions to indicate the end of aline.  GCC accepts the ASCII control sequences @kbd{LF}, @kbd{@w{CRLF}} and @kbd{CR} as end-of-line markers.  These are the canonicalsequences used by Unix, DOS and VMS, and the classic Mac OS (beforeOSX) respectively.  You may therefore safely copy source code writtenon any of those systems to a different one and use it withoutconversion.  (GCC may lose track of the current line number if a filedoesn't consistently use one convention, as sometimes happens when itis edited on computers with different conventions that share a networkfile system.)If the last line of any input file lacks an end-of-line marker, the endof the file is considered to implicitly supply one.  The C standard saysthat this condition provokes undefined behavior, so GCC will emit awarning message.@item@cindex trigraphs@anchor{trigraphs}If trigraphs are enabled, they are replaced by theircorresponding single characters.  By default GCC ignores trigraphs,but if you request a strictly conforming mode with the @option{-std}option, or you specify the @option{-trigraphs} option, then itconverts them.These are nine three-character sequences, all starting with @samp{??},that are defined by ISO C to stand for single characters.  They permitobsolete systems that lack some of C's punctuation to use C@.  Forexample, @samp{??/} stands for @samp{\}, so @t{'??/n'} is a characterconstant for a newline.Trigraphs are not popular and many compilers implement themincorrectly.  Portable code should not rely on trigraphs being eitherconverted or ignored.  With @option{-Wtrigraphs} GCC will warn youwhen a trigraph may change the meaning of your program if it wereconverted.  @xref{Wtrigraphs}.In a string constant, you can prevent a sequence of question marksfrom being confused with a trigraph by inserting a backslash betweenthe question marks, or by separating the string literal at thetrigraph and making use of string literal concatenation.  @t{"(??\?)"}is the string @samp{(???)}, not @samp{(?]}.  Traditional C compilersdo not recognize these idioms.The nine trigraphs and their replacements are@smallexampleTrigraph:       ??(  ??)  ??<  ??>  ??=  ??/  ??'  ??!  ??-

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -