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

📄 cpp.texinfo

📁 这是完整的gcc源代码
💻 TEXINFO
📖 第 1 页 / 共 5 页
字号:
\input texinfo@setfilename cpp.info@settitle The C Preprocessor@setchapternewpage odd@ifinfoThis file documents the GNU C Preprocessor.Copyright (C) 1987, 1989 Free Software Foundation, Inc.Permission is granted to make and distribute verbatim copies ofthis manual provided the copyright notice and this permission noticeare preserved on all copies.@ignorePermission is granted to process this file through Tex and print theresults, provided the printed document carries copying permissionnotice identical to this one except for the removal of this paragraph(this paragraph not being relevant to the printed manual).@end ignorePermission is granted to copy and distribute modified versions of thismanual under the conditions for verbatim copying, provided also thatthe entire resulting derived work is distributed under the terms of apermission notice identical to this one.Permission is granted to copy and distribute translations of this manualinto another language, under the above conditions for modified versions.@end ifinfo@titlepage@sp 6@center @titlefont{The C Preprocessor}@sp 4@center Last revised July 1990@center for GCC version 1.38@sp 5@center Richard M. Stallman@page@vskip 0pt plus 1filllCopyright @copyright{} 1987, 1989 Free Software Foundation, Inc.Permission is granted to make and distribute verbatim copies ofthis manual provided the copyright notice and this permission noticeare preserved on all copies.Permission is granted to copy and distribute modified versions of thismanual under the conditions for verbatim copying, provided also thatthe entire resulting derived work is distributed under the terms of apermission notice identical to this one.Permission is granted to copy and distribute translations of this manualinto another language, under the above conditions for modified versions.@end titlepage@page@node Top, Global Actions,, (DIR)@chapter The C PreprocessorThe C preprocessor is a @dfn{macro processor} that is used automatically bythe C compiler to transform your program before actual compilation.  It iscalled a macro processor because it allows you to define @dfn{macros},which are brief abbreviations for longer constructs.The C preprocessor provides four separate facilities that you can use asyou see fit:@itemize @bullet@itemInclusion of header files.  These are files of declarations that can besubstituted into your program.@itemMacro expansion.  You can define @dfn{macros}, which are abbreviationsfor arbitrary fragments of C code, and then the C preprocessor willreplace the macros with their definitions throughout the program.@itemConditional compilation.  Using special preprocessor commands, youcan include or exclude parts of the program according to variousconditions.@itemLine control.  If you use a program to combine or rearrange source files intoan intermediate file which is then compiled, you can use line controlto inform the compiler of where each source line originally came from.@end itemizeC preprocessors vary in some details.  This manual discusses the GNU Cpreprocessor, the C Compatible Compiler Preprocessor.  The GNU Cpreprocessor provides a superset of the features of ANSI Standard C.ANSI Standard C requires the rejection of many harmless constructs commonlyused by today's C programs.  Such incompatibility would be inconvenient forusers, so the GNU C preprocessor is configured to accept these constructsby default.  Strictly speaking, to get ANSI Standard C, you must use theoptions @samp{-trigraphs}, @samp{-undef} and @samp{-pedantic}, but inpractice the consequences of having strict ANSI Standard C make itundesirable to do this.  @xref{Invocation}.@menu* Global Actions::    Actions made uniformly on all input files.* Commands::          General syntax of preprocessor commands.* Header Files::      How and why to use header files.* Macros::            How and why to use macros.* Conditionals::      How and why to use conditionals.* Combining Sources:: Use of line control when you combine source files.* Other Commands::    Miscellaneous preprocessor commands.* Output::            Format of output from the C preprocessor.* Invocation::        How to invoke the preprocessor; command options.* Concept Index::     Index of concepts and terms.* Index::             Index of commands, predefined macros and options.@end menu@node Global Actions, Commands, Top, Top@section Transformations Made GloballyMost C preprocessor features are inactive unless you give specific commandsto request their use.  (Preprocessor commands are lines starting with@samp{#}; @pxref{Commands}).  But there are three transformations that thepreprocessor always makes on all the input it receives, even in the absenceof commands.@itemize @bullet@itemAll C comments are replaced with single spaces.@itemBackslash-Newline sequences are deleted, no matter where.  Thisfeature allows you to break long lines for cosmetic purposes withoutchanging their meaning.@itemPredefined macro names are replaced with their expansions(@pxref{Predefined}).@end itemizeThe first two transformations are done @emph{before} nearly all other parsingand before preprocessor commands are recognized.  Thus, for example, youcan split a line cosmetically with Backslash-Newline anywhere (exceptwhen trigraphs are in use; see below).@example/**/ # /**/ defi\ne FO\O 10\20@end example@noindentis equivalent into @samp{#define FOO 1020}.  You can split even an escapesequence with Backslash-Newline.  For example, you can split @code{"foo\bar"}between the @samp{\} and the @samp{b} to get@example"foo\\bar"@end example@noindentThis behavior is unclean: in all other contexts, a Backslash can beinserted in a string constant as an ordinary character by writing a doubleBackslash, and this creates an exception.  But the ANSI C standard requiresit.  (Strict ANSI C does not allow Newlines in string constants, so theydo not consider this a problem.)But there are a few exceptions to all three transformations.@itemize @bullet@itemC comments and predefined macro names are not recognized inside a@samp{#include} command in which the file name is delimited with@samp{<} and @samp{>}.@itemC comments and predefined macro names are never recognized within acharacter or string constant.  (Strictly speaking, this is the rule,not an exception, but it is worth noting here anyway.)@itemBackslash-Newline may not safely be used within an ANSI ``trigraph''.Trigraphs are converted before Backslash-Newline is deleted.  If youwrite what looks like a trigraph with a Backslash-Newline inside, theBackslash-Newline is deleted as usual, but it is then too late torecognize the trigraph.This exception is relevant only if you use the @samp{-trigraphs}option to enable trigraph processing.  @xref{Invocation}.@end itemize@node Commands, Header Files, Global Actions, Top@section Preprocessor Commands@cindex preprocessor commands@cindex commandsMost preprocessor features are active only if you use preprocessor commandsto request their use.Preprocessor commands are lines in your program that start with @samp{#}.The @samp{#} is followed by an identifier that is the @dfn{command name}.For example, @samp{#define} is the command that defines a macro.Whitespace is also allowed before and after the @samp{#}.The set of valid command names is fixed.  Programs cannot define newpreprocessor commands.Some command names require arguments; these make up the rest of the commandline and must be separated from the command name by whitespace.  For example,@samp{#define} must be followed by a macro name and the intended expansionof the macro.A preprocessor command cannot be more than one line in normal circumstances.It may be split cosmetically with Backslash-Newline, but that has no effecton its meaning.  Comments containing Newlines can also divide the command intomultiple lines, but the comments are changed to Spaces before the commandis interpreted.  The only way a significant Newline can occur in a preprocessorcommand is within a string constant or character constant.  Note thatmost C compilers that might be applied to the output from the preprocessordo not accept string or character constants containing Newlines.The @samp{#} and the command name cannot come from a macro expansion.  Forexample, if @samp{foo} is defined as a macro expanding to @samp{define},that does not make @samp{#foo} a valid preprocessor command.@node Header Files, Macros, Commands, Top@section Header Files@cindex header fileA header file is a file containing C declarations and macro definitions(@pxref{Macros}) to be shared between several source files.  You requestthe use of a header file in your program with the C preprocessor command@samp{#include}.@menu* Header Uses::         What header files are used for.* Include Syntax::      How to write @samp{#include} commands.* Include Operation::   What @samp{#include} does.* Once-Only::		Preventing multiple inclusion of one header file.@end menu@node Header Uses, Include Syntax, Header Files, Header Files@subsection Uses of Header FilesHeader files serve two kinds of purposes.@itemize @bullet@item@findex system header filesSystem header files declare the interfaces to parts of the operatingsystem.  You include them in your program to supply the definitionsyou need to invoke system calls and libraries.@itemYour own header files contain declarations for interfaces between thesource files of your program.  Each time you have a group of relateddeclarations and macro definitions all or most of which are needed inseveral different source files, it is a good idea to create a headerfile for them.@end itemizeIncluding a header file produces the same results in C compilation ascopying the header file into each source file that needs it.  But suchcopying would be time-consuming and error-prone.  With a header file, therelated declarations appear in only one place.  If they need to be changed,they can be changed in one place, and programs that include the header filewill automatically use the new version when next recompiled.  The headerfile eliminates the labor of finding and changing all the copies as well asthe risk that a failure to find one copy will result in inconsistencieswithin a program.The usual convention is to give header files names that end with @file{.h}.@node Include Syntax, Include Operation, Header Uses, Header Files@subsection The @samp{#include} Command@findex #includeBoth user and system header files are included using the preprocessorcommand @samp{#include}.  It has three variants:@table @code@item #include <@var{file}>This variant is used for system header files.  It searches for a filenamed @var{file} in a list of directories specified by you, then in astandard list of system directories.  You specify directories tosearch for header files with the command option @samp{-I}(@pxref{Invocation}).  The option @samp{-nostdinc} inhibits searchingthe standard system directories; in this case only the directoriesyou specify are searched.The parsing of this form of @samp{#include} is slightly specialbecause comments are not recognized within the @samp{<@dots{}>}.Thus, in @samp{#include <x/*y>} the @samp{/*} does not start a commentand the command specifies inclusion of a system header file named@file{x/*y}.  Of course, a header file with such a name is unlikely toexist on Unix, where shell wildcard features would make it hard tomanipulate.@refillThe argument @var{file} may not contain a @samp{>} character.  It may,however, contain a @samp{<} character.@item #include "@var{file}"This variant is used for header files of your own program.  Itsearches for a file named @var{file} first in the current directory,then in the same directories used for system header files.  Thecurrent directory is the directory of the current input file.  It istried first because it is presumed to be the location of the filesthat the current input file refers to.  (If the @samp{-I-} option isused, the special treatment of the current directory is inhibited.)The argument @var{file} may not contain @samp{"} characters.  Ifbackslashes occur within @var{file}, they are considered ordinary textcharacters, not escape characters.  None of the character escapesequences appropriate to string constants in C are processed.  Thus,@samp{#include "x\n\\y"} specifies a filename containing threebackslashes.  It is not clear why this behavior is ever useful, butthe ANSI standard specifies it.@item #include @var{anything else}This variant is called a @dfn{computed #include}.  Any @samp{#include}command whose argument does not fit the above two forms is a computedinclude.  The text @var{anything else} is checked for macro calls,which are expanded (@pxref{Macros}).  When this is done, the resultmust fit one of the above two variants.This feature allows you to define a macro which controls the file nameto be used at a later point in the program.  One application of thisis to allow a site-configuration file for your program to specify thenames of the system include files to be used.  This can help inporting the program to various operating systems in which thenecessary system header files are found in different places.@end table@node Include Operation, Once-Only, Include Syntax, Header Files@subsection How @samp{#include} WorksThe @samp{#include} command works by directing the C preprocessor to scanthe specified file as input before continuing with the rest of the currentfile.  The output from the preprocessor contains the output alreadygenerated, followed by the output resulting from the included file,followed by the output that comes from the text after the @samp{#include}command.  For example, given two files as follows:@example/* File program.c */int x;#include "header.h"main ()@{  printf (test ());@}

⌨️ 快捷键说明

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