Files
oldlinux-files/study/Ref-docs/C/intro.html
2024-02-19 00:25:23 -05:00

200 lines
8.8 KiB
HTML

<HTML><HEAD><TITLE>Introduction</TITLE></HEAD><BODY BGCOLOR="#FFFFFF">
<H1><A NAME="Introduction">Introduction</A></H1><HR>
<P><B>
<A HREF="#C Standard">C Standard</A>
&#183; <A HREF="#Amendments">Amendments</A>
&#183; <A HREF="#Railroad-Track Diagrams">Railroad-Track Diagrams</A>
&#183; <A HREF="#Notation">Notation</A>
</B></P>
<HR>
<P>``Standard C'' is a term with a fairly precise definition.
This document supplies that definition. It also describes the
notation used throughout this description of Standard C.</P>
<H2><A NAME="C Standard">C Standard</A></H2>
<P>The Standard C programming language described in this document corresponds
to the American National Standards Institute (ANSI) standard for the
C language -- ANSI X3.159-1989. An identical standard was approved
by the International Organization for Standardization (ISO) --
ISO/IEC 9899:1990. This common standard was developed through the
joint efforts of the ANSI-authorized C Programming Language Committee
X3J11 and the ISO authorized Committee JTC1 SC22 WG14.</P>
<P>Standard C is designed to ``codify existing practice.''
Most of the C code written before the advent of Standard C is still
acceptable to one or more Standard C translators. Nevertheless, Standard
C is a new language:</P>
<UL>
<LI>It adds features, such as function prototypes, to correct some
known deficiencies in the C language.</LI>
<LI>It resolves conflicting practices, such as ones found among
the differing rules for redeclaring objects.</LI>
<LI>It clarifies ambiguities, such as whether the objects manipulated
by library functions are permitted to overlap.</LI>
</UL>
<P>This document presents Standard C as a distinct language, not as
a historical outgrowth of any particular earlier dialect of C. If
you are new to C or are familiar with just a specific dialect, you
have a new language to learn.</P>
<H2><A NAME="Amendments">Amendments</A></H2>
<P>The C Standard has more recently been amended and clarified.
<B><A HREF="lib_over.html#Amendment 1" tppabs="http://ccs.ucsd.edu/c/lib_over.html#Amendment 1">Amendment 1</A></B>
(approved in 1994) adds extensive support for manipulating
<A HREF="charset.html#Wide-Character Encoding" tppabs="http://ccs.ucsd.edu/c/charset.html#Wide-Character Encoding">wide characters</A>,
which represent large character sets, and
some additional support for writing source code in national variants of the
ISO 646 character set.
Most of these new features are additions to the
<A HREF="lib_over.html" tppabs="http://ccs.ucsd.edu/c/lib_over.html">library</A>,
and most library additions are defined or declared
in three new headers --
<CODE><A HREF="iso646.html#&lt;iso646.h&gt;" tppabs="http://ccs.ucsd.edu/c/iso646.html#&lt;iso646.h&gt;">&lt;iso646.h&gt;</A></CODE>,
<CODE><A HREF="wchar.html#&lt;wchar.h&gt;" tppabs="http://ccs.ucsd.edu/c/wchar.html#&lt;wchar.h&gt;">&lt;wchar.h&gt;</A></CODE>, and
<CODE><A HREF="wctype.html#&lt;wctype.h&gt;" tppabs="http://ccs.ucsd.edu/c/wctype.html#&lt;wctype.h&gt;">&lt;wctype.h&gt;</A></CODE>.
Many Standard C translators have yet to add these new features,
so this document labels such additions as new with Amendment 1.
For maximum near-term portability, you may wish to avoid them.</P>
<P><B><A NAME="Technical Corrigendum 1">Technical Corrigendum 1</A></B>
(also approved in 1994) supplies a number
of clarifications and corrections to the C Standard. These are in
response to ANSI Requests for Interpretation or ISO Defect Reports
received and processed by X3J11 and WG14 since the C Standard was
first issued. None are intended to alter the original definition of
Standard C, merely to make its definition more unambiguous and precise.
This document reflects the effect of Technical Corrigendum 1, but does
not identify any specific changes.</P>
<H2><A NAME="Railroad-Track Diagrams">Railroad-Track Diagrams</A></H2>
<P>Syntax rules appear in the form of <B>railroad-track diagrams</B>.
The diagrams summarize all valid ways that you can form explicit computer
text for a given form. Not all forms that you can generate from a
railroad-track diagram are necessarily valid. Often semantic restrictions
also apply. These are described in separate tables or in running text.</P>
<P>A railroad-track diagram contains boxes that indicate the components
you use to create a form. Arrows connect the boxes to indicate the
ways that you can combine the components. You can create different
text for a form by taking different paths between the boxes. The name
of the form appears next to the arrow leading out to the right from
the diagram.</P>
<P>Here, for example, is the syntax rule for writing a
<CODE><I>name</I></CODE> in Standard C:</P>
<P><IMG SRC="name.gif" tppabs="http://ccs.ucsd.edu/c/gif/name.gif"></P>
<P>You generate a valid <CODE><I>name</I></CODE> by following the arrows.
Begin with the arrow leading in from the left and continue until you
follow the arrow leading out to the right. In a complex diagram, an
arrow followed by an ellipsis (<CODE>...</CODE>)
connects to the arrow preceded
by an ellipsis immediately below.</P>
<P>Each time you come to a box, you must add the text in the box
to the item being created. If the box contains a form, you must add
text that matches the form. If the box contains more than one entry,
you must add one of the choices. If you come to an intersection with
two arrows leading away from it, you can follow either arrow. You
cannot follow an arrow in the direction opposite to the way it points.</P>
<P>The railroad-track diagram above tells you:</P>
<UL>
<LI>Every name in Standard C begins with either an uppercase or
lowercase <CODE><I>letter</I></CODE>
(such as <CODE>A</CODE> or <CODE>x</CODE>)
or an <CODE><I>underscore</I></CODE> (<CODE>_</CODE>).</LI>
<LI>A name need not contain more than one character.</LI>
<LI>The initial character might be followed by a <CODE><I>digit</I></CODE>
(such as <CODE>3</CODE>), a <CODE><I>letter</I></CODE>,
or an <CODE><I>underscore</I></CODE>.</LI>
<LI>The initial character might be followed by an indefinite number
of these characters.</LI>
</UL>
<P>A name can therefore be any of the following:</P>
<PRE>A A3 _x
timer box_2 z173ab
an_extremely_long_name_that_also_contains_1_digit</PRE>
<P>The syntax rule does <I>not</I> tell you about the following
semantic limitations:</P>
<UL>
<LI>Some implementations can limit the length of the name. (The
limit cannot be less than
<A HREF="portable.html#Translation-Time Issues" tppabs="http://ccs.ucsd.edu/c/portable.html#Translation-Time Issues">509 characters</A>.)</LI>
<LI>An implementation might use only the first
<A HREF="preproc.html#distinct names" tppabs="http://ccs.ucsd.edu/c/preproc.html#distinct names">31 characters</A> when
comparing names.</LI>
<LI>An implementation might use only the first
<A HREF="syntax.html#name" tppabs="http://ccs.ucsd.edu/c/syntax.html#name">six characters</A> and
ignore the difference in case between <CODE>a</CODE> and <CODE>A</CODE>
when comparing names with
<A HREF="declare.html#external linkage" tppabs="http://ccs.ucsd.edu/c/declare.html#external linkage">external linkage</A> from
separate translation units.</LI>
<LI>Names beginning with an <CODE><I>underscore</I></CODE> are generally
<A HREF="lib_over.html#reserved names" tppabs="http://ccs.ucsd.edu/c/lib_over.html#reserved names">reserved</A>
for use by an implementation.</LI>
</UL>
<P>Some diagrams require boxes that permit anything <I>except</I>
one or a few items. In these cases, <CODE><B>bold text</B></CODE>
describes the matching rule. For example, <CODE><B>not</B> NL</CODE>
matches any character except a newline character.</P>
<H2><A NAME="Notation">Notation</A></H2>
<P>A type face that differs from the running text has a special
meaning:</P>
<UL>
<LI><B>definition</B> -- a term that has a special definition
in Standard C.</LI>
<LI><CODE>computer text</CODE> -- any item that can appear explicitly
in a text file, such as C source text, input to a program, or output
from a program.</LI>
<LI><CODE><B>comments</B></CODE> -- remarks that are not an actual part of
the computer text being presented.</LI>
<LI><CODE><I>form</I></CODE> -- a name that stands for one or more explicit
computer text patterns. For example, the following defines
<CODE><I>digit</I></CODE> as a form that you can replace with any of the
explicit characters <CODE>0</CODE>, <CODE>1</CODE>, <CODE>2</CODE>,
and so on:</LI>
</UL>
<PRE><I>digit</I> 0 1 2 3 4 5 6 7 8 9</PRE>
<HR>
<P>See also the
<B><A HREF="index.html#Table of Contents" tppabs="http://ccs.ucsd.edu/c/index.html#Table of Contents">Table of Contents</A></B> and the
<B><A HREF="_index.html" tppabs="http://ccs.ucsd.edu/c/_index.html">Index</A></B>.</P>
<P><I>
<A HREF="crit_pb.html" tppabs="http://ccs.ucsd.edu/c/crit_pb.html">Copyright</A> &#169; 1989-1996
by P.J. Plauger and Jim Brodie. All rights reserved.</I></P>
</BODY></HTML>