📄 library_1.html
字号:
<!-- This HTML file has been created by texi2html 1.27 from library.texinfo on 3 March 1994 --><TITLE>The GNU C Library - Introduction</TITLE><P>Go to the <A HREF="library_2.html" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_2.html">next</A> section.<P><P>@shorttitlepage The GNU C Library Reference ManualThe GNU C Library<P>Reference Manual<P>Sandra LoosemorewithRoland McGrath, Andrew Oram, and Richard M. Stallman<P>last updated 9 April 1993<P>for version 1.06 BetaCopyright (C) 1993 Free Software Foundation, Inc.<P><H1><A NAME="SEC1" HREF="library_toc.html#SEC1" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC1">Introduction</A></H1><P>The 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</DFN>, which you compile and link with yourprograms.<A NAME="IDX1"></A><P>The 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.<P>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 on this manual is not on strictportability.<P><H2><A NAME="SEC2" HREF="library_toc.html#SEC2" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC2">Getting Started</A></H2><P>This 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(see section <A HREF="library_1.html#SEC4" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_1.html#SEC4">ANSI C</A>), rather than "traditional" pre-ANSI C dialects, isassumed.<P>The GNU C library includes several <DFN>header files</DFN>, 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 <TT>`stdio.h'</TT> declares facilities forperforming input and output, and the header file <TT>`string.h'</TT>declares string processing utilities. The organization of this manualgenerally follows the same division as the header files.<P>If you are reading this manual for the first time, you should read allof the introductory material and skim the remaining chapters. There area <EM>lot</EM> of functions in the GNU C library and it's not realistic toexpect that you will be able to remember exactly <EM>how</EM> 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 <EM>when</EM> to make use oflibrary functions, and <EM>where</EM> in this manual you can find morespecific information about them.<P><A NAME="IDX2"></A><H2><A NAME="SEC3" HREF="library_toc.html#SEC3" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC3">Standards and Portability</A></H2><P>This 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.<P>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.<P>See section <A HREF="library_29.html#SEC492" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_29.html#SEC492">Summary of Library Facilities</A>, for an alphabetical list of the functions andother symbols provided by the library. This list also states whichstandards each function or symbol comes from.<P><A NAME="IDX3"></A><H3><A NAME="SEC4" HREF="library_toc.html#SEC4" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC4">ANSI C</A></H3><P>The 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"</CITE>.The header files and library facilities that make up the GNU library area superset of those specified by the ANSI C standard.<A NAME="IDX4"></A><P>If you are concerned about strict adherence to the ANSI C standard, youshould use the <SAMP>`-ansi'</SAMP> option when you compile your programs withthe GNU C compiler. This tells the compiler to define <EM>only</EM> ANSIstandard features from the library header files, unless you explicitlyask for additional features. See section <A HREF="library_1.html#SEC12" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_1.html#SEC12">Feature Test Macros</A>, forinformation on how to do this.<P>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. See section <A HREF="library_1.html#SEC11" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_1.html#SEC11">Reserved Names</A>, for more information about theserestrictions.<P>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.<P><A NAME="IDX5"></A><A NAME="IDX6"></A><A NAME="IDX7"></A><A NAME="IDX8"></A><A NAME="IDX9"></A><H3><A NAME="SEC5" HREF="library_toc.html#SEC5" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC5">POSIX (The Portable Operating System Interface)</A></H3><P>The GNU library is also compatible with the IEEE <DFN>POSIX</DFN> family ofstandards, known more formally as the <DFN>Portable Operating SystemInterface for Computer Environments</DFN>. POSIX is derived mostly fromvarious versions of the Unix operating system.<P>The library facilities specified by the POSIX standard are a superset ofthose required by ANSI C; POSIX specifies additional features for ANSI Cfunctions, as well as specifying new additional functions. In general,the additional requirements and functionality defined by the POSIXstandard are aimed at providing lower-level support for a particularkind of operating system environment, rather than general programminglanguage support which can run in many diverse operating systemenvironments.<P>The GNU C library implements all of the functions specified in<CITE>IEEE Std 1003.1-1988, the POSIX System Application ProgramInterface</CITE>, commonly referred to as POSIX.1. The primary extensions tothe ANSI C facilities specified by this standard include file systeminterface primitives (see section <A HREF="library_13.html#SEC187" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_13.html#SEC187">File System Interface</A>), device-specificterminal control functions (see section <A HREF="library_16.html#SEC268" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_16.html#SEC268">Low-Level Terminal Interface</A>), andprocess control functions (see section <A HREF="library_23.html#SEC401" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_23.html#SEC401">Child Processes</A>).<P>Some facilities from draft 11 of <CITE>IEEE Std 1003.2, the POSIX Shelland Utilities standard</CITE> (POSIX.2) are also implemented in the GNUlibrary. These include utilities for dealing with regular expressionsand other pattern matching facilities (see section <A HREF="library_9.html#SEC91" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_9.html#SEC91">Pattern Matching</A>).<P><A NAME="IDX10"></A><A NAME="IDX11"></A><A NAME="IDX12"></A><A NAME="IDX13"></A><A NAME="IDX14"></A><H3><A NAME="SEC6" HREF="library_toc.html#SEC6" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC6">Berkeley Unix</A></H3><P>The GNU C library defines facilities from some other versions of Unix,specifically from the 4.2 BSD and 4.3 BSD Unix systems (also known as<DFN>Berkeley Unix</DFN>) and from <DFN>SunOS</DFN> (a popular 4.2 BSD derivativethat includes some Unix System V functionality). <P>The BSD facilities include symbolic links (see section <A HREF="library_13.html#SEC196" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_13.html#SEC196">Symbolic Links</A>), the<CODE>select</CODE> function (see section <A HREF="library_12.html#SEC180" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_12.html#SEC180">Waiting for Input or Output</A>), the BSD signalfunctions (see section <A HREF="library_21.html#SEC380" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_21.html#SEC380">BSD Signal Handling</A>), and sockets (see section <A HREF="library_15.html#SEC216" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_15.html#SEC216">Sockets</A>).<P><A NAME="IDX15"></A><A NAME="IDX16"></A><A NAME="IDX17"></A><H3><A NAME="SEC7" HREF="library_toc.html#SEC7" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC7">SVID (The System V Interface Description)</A></H3><P>The <DFN>System V Interface Description</DFN> (SVID) is a document describingthe AT&T Unix System V operating system. It is to some extent asuperset of the POSIX standard (see section <A HREF="library_1.html#SEC5" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_1.html#SEC5">POSIX (The Portable Operating System Interface)</A>).<P>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.)<P><STRONG>Incomplete:</STRONG> Are there any particular System V facilities thatought to be mentioned specifically here?<P><H2><A NAME="SEC8" HREF="library_toc.html#SEC8" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC8">Using the Library</A></H2><P>This section describes some of the practical issues involved in usingthe GNU C library.<P><A NAME="IDX18"></A><H3><A NAME="SEC9" HREF="library_toc.html#SEC9" tppabs="http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_toc.html#SEC9">Header Files</A></H3><P>Libraries for use by C programs really consist of two parts: <DFN>headerfiles</DFN> that define types and macros and declare variables andfunctions; and the actual library or <DFN>archive</DFN> that contains thedefinitions of the variables and functions.<P>(Recall that in C, a <DFN>declaration</DFN> 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</DFN>, on the other hand, actually allocates storage for avariable or says what a function does.)<A NAME="IDX20"></A><A NAME="IDX19"></A><P>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.<P>Header files are included into a program source file by the<SAMP>`#include'</SAMP> preprocessor directive. The C language supports twoforms of this directive; the first,<P><PRE>#include "<VAR>header</VAR>"</PRE><P>is typically used to include a header file <VAR>header</VAR> that you writeyourself; this would contain definitions and declarations describing theinterfaces between the different parts of your particular application.By contrast,<P><PRE>#include <file.h></PRE><P>is typically used to include a header file <TT>`file.h'</TT> 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.<P>Typically, <SAMP>`#include'</SAMP> 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'</SAMP> directives immediately afterwards, following the
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -