?? 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 Manual
The GNU C Library
<P>
Reference Manual
<P>
Sandra Loosemore
with
Roland McGrath, Andrew Oram, and Richard M. Stallman
<P>
last updated 9 April 1993
<P>
for version 1.06 Beta
Copyright (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 such
common operations as input/output, memory management, string
manipulation, and the like. Instead, these facilities are defined
in a standard <DFN>library</DFN>, which you compile and link with your
programs.
<A NAME="IDX1"></A>
<P>
The GNU C library, described in this document, defines all of the
library functions that are specified by the ANSI C standard, as well as
additional features specific to POSIX and other derivatives of the Unix
operating system, and extensions specific to the GNU system.
<P>
The purpose of this manual is to tell you how to use the facilities
of the GNU library. We have mentioned which features belong to which
standards to help you identify things that are potentially nonportable
to other systems. But the emphasis on this manual is not on strict
portability.
<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 least
somewhat familiar with the C programming language and basic programming
concepts. 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, is
assumed.
<P>
The GNU C library includes several <DFN>header files</DFN>, each of which
provides 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 for
performing input and output, and the header file <TT>`string.h'</TT>
declares string processing utilities. The organization of this manual
generally follows the same division as the header files.
<P>
If you are reading this manual for the first time, you should read all
of the introductory material and skim the remaining chapters. There are
a <EM>lot</EM> of functions in the GNU C library and it's not realistic to
expect that you will be able to remember exactly <EM>how</EM> to use each
and every one of them. It's more important to become generally familiar
with the kinds of facilities that the library provides, so that when you
are writing your programs you can recognize <EM>when</EM> to make use of
library functions, and <EM>where</EM> in this manual you can find more
specific 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 the
GNU C library is based upon. These sources include the ANSI C and
POSIX standards, and the System V and Berkeley Unix implementations.
<P>
The primary focus of this manual is to tell you how to make effective
use of the GNU library facilities. But if you are concerned about
making your programs compatible with these standards, or portable to
operating systems other than GNU, this can affect how you use the
library. This section gives you an overview of these standards, so that
you will know what they are when they are mentioned in other parts of
the 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 and
other symbols provided by the library. This list also states which
standards 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 the
American 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 are
a 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, you
should use the <SAMP>`-ansi'</SAMP> option when you compile your programs with
the GNU C compiler. This tells the compiler to define <EM>only</EM> ANSI
standard features from the library header files, unless you explicitly
ask 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>, for
information on how to do this.
<P>
Being able to restrict the library to include only ANSI C features is
important because ANSI C puts limitations on what names can be defined
by the library implementation, and the GNU extensions don't fit these
limitations. 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 these
restrictions.
<P>
This manual does not attempt to give you complete details on the
differences between ANSI C and older dialects. It gives advice on how
to write programs to work portably under multiple C dialects, but does
not 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 of
standards, known more formally as the <DFN>Portable Operating System
Interface for Computer Environments</DFN>. POSIX is derived mostly from
various versions of the Unix operating system.
<P>
The library facilities specified by the POSIX standard are a superset of
those required by ANSI C; POSIX specifies additional features for ANSI C
functions, as well as specifying new additional functions. In general,
the additional requirements and functionality defined by the POSIX
standard are aimed at providing lower-level support for a particular
kind of operating system environment, rather than general programming
language support which can run in many diverse operating system
environments.<P>
The GNU C library implements all of the functions specified in
<CITE>IEEE Std 1003.1-1988, the POSIX System Application Program
Interface</CITE>, commonly referred to as POSIX.1. The primary extensions to
the ANSI C facilities specified by this standard include file system
interface 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-specific
terminal 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>), and
process 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 Shell
and Utilities standard</CITE> (POSIX.2) are also implemented in the GNU
library. These include utilities for dealing with regular expressions
and 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 derivative
that 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 signal
functions (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 describing
the AT&T Unix System V operating system. It is to some extent a
superset 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 SVID
that are not also required by the ANSI or POSIX standards, for
compatibility with System V Unix and other Unix systems (such as
SunOS) which include these facilities. However, many of the more
obscure and less generally useful facilities required by the SVID are
not included. (In fact, Unix System V itself does not provide them all.)
<P>
<STRONG>Incomplete:</STRONG> Are there any particular System V facilities that
ought 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 using
the 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>header
files</DFN> that define types and macros and declare variables and
functions; and the actual library or <DFN>archive</DFN> that contains the
definitions of the variables and functions.
<P>
(Recall that in C, a <DFN>declaration</DFN> merely provides information that
a function or variable exists and gives its type. For a function
declaration, information about the types of its arguments might be
provided as well. The purpose of declarations is to allow the compiler
to correctly process references to the declared variables and functions.
A <DFN>definition</DFN>, on the other hand, actually allocates storage for a
variable 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 sure
that your program source files include the appropriate header files.
This is so that the compiler has declarations of these facilities
available and can correctly process references to them. Once your
program has been compiled, the linker resolves these references to
the 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 two
forms 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 write
yourself; this would contain definitions and declarations describing the
interfaces 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 contains
definitions and declarations for a standard library. This file would
normally 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 C
source file, before any other code. If you begin your source files with
some 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 + -