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

📄 intro.texi

📁 一个C源代码分析器
💻 TEXI
📖 第 1 页 / 共 2 页
字号:
@node Introduction, Error Reporting, Top, Top@chapter IntroductionThe C language provides no built-in facilities for performing suchcommon operations as input/output, memory management, stringmanipulation, and the like.  Instead, these facilities are definedin a standard @dfn{library}, which you compile and link with yourprograms.@cindex libraryThe GNU C library, described in this document, defines all of thelibrary functions that are specified by the ANSI C standard, as well asadditional features specific to POSIX and other derivatives of the Unixoperating system, and extensions specific to the GNU system.The purpose of this manual is to tell you how to use the facilitiesof the GNU library.  We have mentioned which features belong to whichstandards to help you identify things that are potentially nonportableto other systems.  But the emphasis in this manual is not on strictportability.@menu* Getting Started::             What this manual is for and how to use it.* Standards and Portability::   Standards and sources upon which the GNU                                 C library is based.* Using the Library::           Some practical uses for the library.* Roadmap to the Manual::       Overview of the remaining chapters in                                 this manual.@end menu@node Getting Started, Standards and Portability,  , Introduction@section Getting StartedThis manual is written with the assumption that you are at leastsomewhat familiar with the C programming language and basic programmingconcepts.  Specifically, familiarity with ANSI standard C(@pxref{ANSI C}), rather than ``traditional'' pre-ANSI C dialects, isassumed.The GNU C library includes several @dfn{header files}, each of whichprovides definitions and declarations for a group of related facilities;this information is used by the C compiler when processing your program.For example, the header file @file{stdio.h} declares facilities forperforming input and output, and the header file @file{string.h}declares string processing utilities.  The organization of this manualgenerally follows the same division as the header files.If you are reading this manual for the first time, you should read allof the introductory material and skim the remaining chapters.  There area @emph{lot} of functions in the GNU C library and it's not realistic toexpect that you will be able to remember exactly @emph{how} to use eachand every one of them.  It's more important to become generally familiarwith the kinds of facilities that the library provides, so that when youare writing your programs you can recognize @emph{when} to make use oflibrary functions, and @emph{where} in this manual you can find morespecific information about them.@node Standards and Portability, Using the Library, Getting Started, Introduction@section Standards and Portability@cindex standardsThis section discusses the various standards and other sources that theGNU C library is based upon.  These sources include the ANSI C andPOSIX standards, and the System V and Berkeley Unix implementations.The primary focus of this manual is to tell you how to make effectiveuse of the GNU library facilities.  But if you are concerned aboutmaking your programs compatible with these standards, or portable tooperating systems other than GNU, this can affect how you use thelibrary.  This section gives you an overview of these standards, so thatyou will know what they are when they are mentioned in other parts ofthe manual.@xref{Library Summary}, for an alphabetical list of the functions andother symbols provided by the library.  This list also states whichstandards each function or symbol comes from.@menu* ANSI C::                      The American National Standard for the				 C programming language.  * POSIX::                       The IEEE 1003 standards for operating                                 systems. * Berkeley Unix::               BSD and SunOS.* SVID::                        The System V Interface Description.  @end menu@node ANSI C, POSIX,  , Standards and Portability@subsection ANSI C@cindex ANSI CThe GNU C library is compatible with the C standard adopted by theAmerican National Standards Institute (ANSI):@cite{American National Standard X3.159-1989---``ANSI C''}.The header files and library facilities that make up the GNU library area superset of those specified by the ANSI C standard.@refill@pindex gccIf you are concerned about strict adherence to the ANSI C standard, youshould use the @samp{-ansi} option when you compile your programs withthe GNU C compiler.  This tells the compiler to define @emph{only} ANSIstandard features from the library header files, unless you explicitlyask for additional features.  @xref{Feature Test Macros}, forinformation on how to do this.Being able to restrict the library to include only ANSI C features isimportant because ANSI C puts limitations on what names can be definedby the library implementation, and the GNU extensions don't fit theselimitations.  @xref{Reserved Names}, for more information about theserestrictions.This manual does not attempt to give you complete details on thedifferences between ANSI C and older dialects.  It gives advice on howto write programs to work portably under multiple C dialects, but doesnot aim for completeness.@node POSIX, Berkeley Unix, ANSI C, Standards and Portability@subsection POSIX (The Portable Operating System Interface)@cindex POSIX@cindex POSIX.1@cindex IEEE Std 1003.1@cindex POSIX.2@cindex IEEE Std 1003.2The GNU library is also compatible with the IEEE @dfn{POSIX} family ofstandards, known more formally as the @dfn{Portable Operating SystemInterface for Computer Environments}.  POSIX is derived mostly fromvarious versions of the Unix operating system.The library facilities specified by the POSIX standards are a supersetof those required by ANSI C; POSIX specifies additional features forANSI C functions, as well as specifying new additional functions.  Ingeneral, the additional requirements and functionality defined by thePOSIX standards are aimed at providing lower-level support for aparticular kind of operating system environment, rather than generalprogramming language support which can run in many diverse operatingsystem environments.@refillThe GNU C library implements all of the functions specified in@cite{IEEE Std 1003.1-1990, the POSIX System Application ProgramInterface}, commonly referred to as POSIX.1.  The primary extensions tothe ANSI C facilities specified by this standard include file systeminterface primitives (@pxref{File System Interface}), device-specificterminal control functions (@pxref{Low-Level Terminal Interface}), andprocess control functions (@pxref{Processes}).Some facilities from @cite{IEEE Std 1003.2-1992, the POSIX Shell andUtilities standard} (POSIX.2) are also implemented in the GNU library.These include utilities for dealing with regular expressions and otherpattern matching facilities (@pxref{Pattern Matching}).@comment Roland sez:@comment The GNU C library as it stands conforms to 1003.2 draft 11, which@comment specifies:@comment @comment Several new macros in <limits.h>.@comment popen, pclose@comment <regex.h> (which is not yet fully implemented--wait on this)@comment fnmatch@comment getopt@comment <glob.h>@comment <wordexp.h> (not yet implemented)@comment confstr@node Berkeley Unix, SVID, POSIX, Standards and Portability@subsection Berkeley Unix@cindex BSD Unix@cindex 4.@var{n} BSD Unix@cindex Berkeley Unix@cindex SunOS@cindex Unix, BerkeleyThe GNU C library defines facilities from some versions of Unix whichare not formally standardized, specifically from the 4.2 BSD, 4.3 BSD,and 4.4 BSD Unix systems (also known as @dfn{Berkeley Unix}) and from@dfn{SunOS} (a popular 4.2 BSD derivative that includes some Unix SystemV functionality).  These systems support most of the ANSI and POSIXfacilities, and 4.4 BSD and newer releases of SunOS in fact support them all.The BSD facilities include symbolic links (@pxref{Symbolic Links}), the@code{select} function (@pxref{Waiting for I/O}), the BSD signalfunctions (@pxref{BSD Signal Handling}), and sockets (@pxref{Sockets}).@node SVID,  , Berkeley Unix, Standards and Portability@subsection SVID (The System V Interface Description)@cindex SVID@cindex System V Unix@cindex Unix, System VThe @dfn{System V Interface Description} (SVID) is a document describingthe AT&T Unix System V operating system.  It is to some extent asuperset of the POSIX standard (@pxref{POSIX}).The GNU C library defines some of the facilities required by the SVIDthat are not also required by the ANSI or POSIX standards, forcompatibility with  System V Unix and other Unix systems (such asSunOS) which include these facilities.  However, many of the moreobscure and less generally useful facilities required by the SVID arenot included.  (In fact, Unix System V itself does not provide them all.)@c !!! mention sysv ipc/shmem when it is there.@node Using the Library, Roadmap to the Manual, Standards and Portability, Introduction@section Using the LibraryThis section describes some of the practical issues involved in usingthe GNU C library.@menu* Header Files::                How to include the header files in your                                 programs. * Macro Definitions::           Some functions in the library may really                                 be implemented as macros.* Reserved Names::              The C standard reserves some names for                                 the library, and some for users.* Feature Test Macros::         How to control what names are defined.@end menu@node Header Files, Macro Definitions,  , Using the Library@subsection Header Files@cindex header filesLibraries for use by C programs really consist of two parts: @dfn{headerfiles} that define types and macros and declare variables andfunctions; and the actual library or @dfn{archive} that contains thedefinitions of the variables and functions.(Recall that in C, a @dfn{declaration} merely provides information thata function or variable exists and gives its type.  For a functiondeclaration, information about the types of its arguments might beprovided as well.  The purpose of declarations is to allow the compilerto correctly process references to the declared variables and functions.A @dfn{definition}, on the other hand, actually allocates storage for avariable or says what a function does.)@cindex definition (compared to declaration)@cindex declaration (compared to definition)In order to use the facilities in the GNU C library, you should be surethat your program source files include the appropriate header files.This is so that the compiler has declarations of these facilitiesavailable and can correctly process references to them.  Once yourprogram has been compiled, the linker resolves these references tothe actual definitions provided in the archive file.Header files are included into a program source file by the@samp{#include} preprocessor directive.  The C language supports twoforms of this directive; the first,@smallexample#include "@var{header}"@end smallexample@noindentis typically used to include a header file @var{header} that you writeyourself; this would contain definitions and declarations describing theinterfaces between the different parts of your particular application.By contrast,@smallexample#include <file.h>@end smallexample@noindentis typically used to include a header file @file{file.h} that containsdefinitions and declarations for a standard library.  This file wouldnormally be installed in a standard place by your system administrator.You should use this second form for the C library header files.Typically, @samp{#include} directives are placed at the top of the Csource file, before any other code.  If you begin your source files withsome comments explaining what the code in the file does (a good idea),put the @samp{#include} directives immediately afterwards, following thefeature test macro definition (@pxref{Feature Test Macros}).For more information about the use of header files and @samp{#include}directives, @pxref{Header Files,,, cpp.info, The GNU C PreprocessorManual}.@refillThe GNU C library provides several header files, each of which containsthe type and macro definitions and variable and function declarationsfor a group of related facilities.  This means that your programs mayneed to include several header files, depending on exactly whichfacilities you are using.Some library header files include other library header filesautomatically.  However, as a matter of programming style, you shouldnot rely on this; it is better to explicitly include all the headerfiles required for the library facilities you are using.  The GNU Clibrary header files have been written in such a way that it doesn'tmatter if a header file is accidentally included more than once;including a header file a second time has no effect.  Likewise, if yourprogram needs to include multiple header files, the order in which theyare included doesn't matter.@strong{Compatibility Note:} Inclusion of standard header files in anyorder and any number of times works in any ANSI C implementation.However, this has traditionally not been the case in many older Cimplementations.Strictly speaking, you don't @emph{have to} include a header file to usea function it declares; you could declare the function explicitlyyourself, according to the specifications in this manual.  But it isusually better to include the header file because it may define typesand macros that are not otherwise available and because it may definemore efficient macro replacements for some functions.  It is also a sureway to have the correct declaration.@node Macro Definitions, Reserved Names, Header Files, Using the Library@subsection Macro Definitions of Functions@cindex shadowing functions with macros@cindex removing macros that shadow functions@cindex undefining macros that shadow functionsIf we describe something as a function in this manual, it may have amacro definition as well.  This normally has no effect on how yourprogram runs---the macro definition does the same thing as the functionwould.  In particular, macro equivalents for library functions evaluatearguments exactly once, in the same way that a function call would.  Themain reason for these macro definitions is that sometimes they canproduce an inline expansion that is considerably faster than an actualfunction call.Taking the address of a library function works even if it is alsodefined as a macro.  This is because, in this context, the name of thefunction isn't followed by the left parenthesis that is syntacticallynecessary to recognize a macro call.You might occasionally want to avoid using the macro definition of afunction---perhaps to make your program easier to debug.  There aretwo ways you can do this:@itemize @bullet@item You can avoid a macro definition in a specific use by enclosing the nameof the function in parentheses.  This works because the name of thefunction doesn't appear in a syntactic context where it is recognizableas a macro call.@itemYou can suppress any macro definition for a whole source file by usingthe @samp{#undef} preprocessor directive, unless otherwise statedexplicitly in the description of that facility.

⌨️ 快捷键说明

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