home *** CD-ROM | disk | FTP | other *** search
/ ftp.cse.unsw.edu.au / 2014.06.ftp.cse.unsw.edu.au.tar / ftp.cse.unsw.edu.au / pub / doc / papers / misc / cs.toronto.edu:programming / ansi-c.summary next >
Encoding:
Text File  |  1992-10-18  |  31.9 KB  |  975 lines

  1. Newsgroups: comp.std.c
  2. Path: news-server.csri.toronto.edu!utgpu!watserv1!maytag!csg.uwaterloo.ca!giguere
  3. From: giguere@csg.uwaterloo.ca (Eric Giguere)
  4. Subject: Re: Ansi C reference guide
  5. Message-ID: <1990Aug29.194116.8274@maytag.waterloo.edu>
  6. Keywords: Ansi C books
  7. Sender: daemon@maytag.waterloo.edu (Admin)
  8. Organization: Computer Systems Group, U of Waterloo
  9. References: <12836@netcom.UUCP>
  10. Date: Wed, 29 Aug 90 19:41:16 GMT
  11. Lines: 962
  12.  
  13. For those who wonder about ANSI C, a somewhat outdated but still useful
  14. document I wrote....  But please don't flame me for omissions or errors!
  15. Just send me polite email... this was done in 1987 and I really haven't
  16. looked at it since.
  17.  
  18.  --------------------------cut here-------------------------------------
  19.  
  20.  
  21.  Author's Note:  The following summary was originally written for inclusion
  22.  --------------  with the Waterloo C compiler (VM/CMS) and has also been
  23.                  published as an article in the Transactor for the Amiga
  24.                  (vol 1 no 3).  I wrote it in 1987 and it has not yet been
  25.                  updated to reflect the final version of the Standard.  I
  26.                  think, however, that it still presents the major changes
  27.                  quite nicely.  You can also check out the second edition
  28.                  of K&R for more information.  This document was orginally
  29.                  done using Script/GML --- basically I just removed the
  30.                  formatting macros, which explains the weird spacing and
  31.                  varying line lengths.  If there is enough interest I may
  32.                  polish this document up into TeX format and update it
  33.                  to reflect the final Standard.
  34.  
  35.  
  36.  
  37.  
  38.  
  39.          The ANSI Standard: A Summary for the C Programmer
  40.  
  41.  
  42.                           Eric Giguere
  43.                      Computer Systems Group
  44.                      University of Waterloo
  45.                     giguere@csg.uwaterloo.ca
  46.  
  47.                        December 18, 1987
  48.  
  49.  
  50.          This document is Copyright (c)1987 by Eric Giguere.
  51.          Permission is granted to use and distribute this
  52.          document for non-commercial purposes.
  53.  
  54.  
  55.  
  56. Introduction
  57. ------------
  58.  
  59. Programming languages are constantly evolving and diversifying.
  60. The C language is no exception, especially due to its increased
  61. popularity in recent years.  The original specification document
  62. for C, "The C Programming Language"
  63. by Brian Kernighan and Dennis Ritchie (commonly referred to
  64. as K&R), is now almost ten years old.
  65. K&R has served as the C programmer's "bible", the de facto
  66. standard for C.  But as the language has evolved,
  67. the need for a formal language standard has become apparent.
  68.  
  69. Under the auspices of the International Standards Organization (ISO),
  70. the American National Standards Institute (ANSI) began the preparation
  71. of such a standard through the leadership of the X3J11 Technical
  72. Committee.  The proposed standard is now in final draft form and is
  73. expected to be approved by ANSI and ISO in 1988.
  74.  
  75. This document is a summary of the proposed standard's major changes
  76. to the language as it pertains to the C programmer.  All information
  77. is drawn from official X3J11 documents:  the
  78. "Draft Proposed American National Standard for Information
  79. Systems - Programming Language C"
  80. and the accompanying
  81. "Rationale for Draft Proposed National Standard for Information
  82. Systems - Programming Language C".
  83. (These publications will be referred to as the Standard and the
  84. Rationale, respectively.)
  85.  
  86.  
  87. Purpose of the Summary
  88. ----------------------
  89.  
  90. Few programmers have either the time or the interest
  91. to wade through the actual text of the draft Standard
  92. in its entirety.  What interests them are the
  93. major points of the Standard and the changes
  94. it makes to what was defined in K&R
  95. and how it affects their current programs.
  96. By summarizing these changes, this document is intended
  97. to provide a
  98. quick reference that the average C programmer can read
  99. and understand in one session.  In keeping with this goal,
  100. the Standard Library is only briefly mentioned.  Readers
  101. interested in the specifics of the Library should consult
  102. the Standard itself or the documentation accompanying
  103. any ANSI-conforming compiler.
  104.  
  105. This document is not
  106. a criticism or a justification
  107. of the Standard, only a commentary.
  108. Nor is it a tutorial on the C programming language.
  109. Readers should
  110. also be aware that changes may occur to the Standard before its
  111. final acceptance by ANSI.
  112.  
  113.  
  114. What to expect from the Standard
  115. --------------------------------
  116.  
  117. The Standard is not
  118. creating a new language definition.  Its purpose, to quote
  119. the Rationale, is to "codify common existing practice".  This
  120. means that the fundamental structure and syntax of the language
  121. as described in K&R has been left unchanged.  The Standard has
  122. instead tried to unify the diverse extensions and dialects
  123. that have grown over the years
  124. (the existing practice)
  125. into a single cohesive language definition.  Existing
  126. practice is often inconsistent, however, so many compromises
  127. have had to be made.
  128.  
  129. Perhaps the most important thing to remember about the Standard
  130. is that it is not intended to invalidate existing C code.
  131. Existing programs should compile with only minor changes
  132. when using an ANSI-conformant compiler.
  133.  
  134.  
  135. Common Terms
  136. ------------
  137.  
  138. Throughout this document the word implementation
  139. will be used to refer to any particular implementation
  140. of an ANSI-conformant C language interpreter or compiler.
  141.  
  142.  
  143. 1. Reserved Identifiers
  144. -----------------------
  145.  
  146. The following keywords have been added to the language:
  147.  
  148.           const
  149.           enum
  150.           signed
  151.           void
  152.           volatile
  153.  
  154. Explanations for each keyword follow in Sections 2 and 4.
  155. In addition, the identifier "entry"
  156. has been deleted from the list of reserved identifiers as it
  157. was never implemented by K&R or subsequent versions of C.
  158.  
  159. Each keyword is a reserved identifier; programs that currently
  160. use these keywords as variable names must be changed to compile
  161. under an ANSI-conformant implementation.
  162.  
  163. 2. Data Types
  164. -------------
  165.  
  166. Major language changes occur with respect to data types.
  167. The trend in the Standard has been to provide the language
  168. with stronger typing facilities.
  169.  
  170. Integers
  171. --------
  172.  
  173. The list of available integer types has been
  174. expanded to include "signed char"
  175. and the following variations:
  176.  
  177.           unsigned int     signed int
  178.           unsigned long    signed long
  179.           unsigned short   signed short
  180.  
  181. "long int" and "short int" may also be used as variations of
  182. "long" and "short", respectively.  As would be expected, the declarations:
  183.  
  184.           signed x;
  185.           unsigned y;
  186.  
  187. may be used as shorthand for "signed int" and "unsigned int".
  188. All logical combinations for integer types are now allowed.
  189.  
  190. Whether or not a simple "char" is considered to be signed or unsigned
  191. is left up to the implementation.
  192.  
  193. While int is still the default type for variables and functions,
  194. at least one storage class (auto, register, static, extern)
  195. or type specifier must be present when declaring a variable.
  196. A declaration of the form:
  197.  
  198.           x;
  199.  
  200. is no longer allowed and must be replaced with:
  201.  
  202.           int x;
  203.  
  204. to compile.
  205.  
  206. Floats
  207. ------
  208.  
  209. The new type "long double" has been added for more precision.  But like any
  210. "long" type, an object of this type is only guaranteed to be
  211. at least as large as a "double".
  212.  
  213. The type "long float" (a previous synonym for double)
  214. is now invalid.  The only acceptable floating-point types are
  215. float, double and long double.
  216.  
  217. Structures and Unions
  218. ---------------------
  219.  
  220. Member name spaces are now unique within structures and unions.
  221. That is, two different structures or unions may contain members with
  222. the same name without fear of conflict.
  223.  
  224. Structures and unions may now:
  225.  
  226.   * be assigned to another of the same type
  227.   * be initialized when declared with the auto storage class
  228.   * be passed as function parameters and return values
  229.  
  230. Enumerations
  231. ------------
  232.  
  233. Already available in most compilers, enumerations have been
  234. added to the language.  An enumeration is a way
  235. of declaring a set of integer constants.  The declaration:
  236.  
  237.     enum colours { RED, BLUE, GREEN };
  238.  
  239. would declare "colours"
  240. as an enumeration tag representing the integer constants
  241. RED, BLUE and GREEN.
  242. These enumeration constants are given integer values starting
  243. at 0 and increasing by 1 with each identifier.
  244.  
  245. An enumeration
  246. constant may be used wherever an integer is expected.
  247. The following is equivalent to the above enumerated type:
  248.  
  249.     #define RED   0
  250.     #define BLUE  1
  251.     #define GREEN 2
  252.  
  253. Enumeration constants are not restricted to upper case, but
  254. upper case is a widely recognized convention for constants.
  255.  
  256. Variables may be declared to have enumeration type.
  257. The declaration:
  258.  
  259.     enum colours x, y;
  260.  
  261. declares x and y to be integer variables capable of holding an enumeration
  262. constant of type "colours".
  263. In practice, little or no checking is done to make sure enumeration
  264. constants are used, so the following assignments are equivalent:
  265.  
  266.     x = BLUE;
  267.     x = 1;   /* defeats purpose of enum */
  268.  
  269. Constant values may be directly assigned within an enumeration
  270. as well:
  271.  
  272.     enum relation { EQUAL = 1, LESS_THAN = 2,
  273.                     GREATER_THAN = 4 };
  274.  
  275. If no value is specified for a given identifier, the constant
  276. is taken to have the value of the previous constant plus one.
  277.  
  278. The size of an enumeration type has been left unspecified;
  279. the implementation is free to store it in the most optimal
  280. fashion, providing that it always behaves like an int.
  281.  
  282. Void Type
  283. ---------
  284.  
  285. The "void" data type has been added to indicate that an expression has
  286. no value.  No variables can be declared with such a type, but
  287. expressions may be cast to void.
  288.  
  289. For example, the following declaration:
  290.  
  291.     (void) printf( "hello world" );
  292.  
  293. specifically indicates to the compiler that the return value
  294. from printf (an integer) is to be ignored.  As such,
  295. the following statement is illegal:
  296.  
  297.     a = (void) func(); /* illegal! */
  298.  
  299. since the assignment operator expects a value to be returned for
  300. assignment.
  301.  
  302. Void pointers and void functions are discussed below and in Section 4.
  303.  
  304. Pointers and Arrays
  305. -------------------
  306.  
  307. Pointers are no longer synonymous with the "int"
  308. type.  Pointers may only be compared with or assigned:
  309.  
  310.   * the integer value 0 (used to define a null pointer)
  311.   * a pointer of the same type
  312.   * a pointer of generic type (a void pointer)
  313.  
  314. Any other use of a pointer will generate a warning message
  315. upon compilation.  Many assignment statements will require
  316. explicit casting of the right-hand values to avoid generating
  317. these messages.
  318.  
  319. A void pointer is a pointer that has no base type --- that is, it points
  320. to a type of unknown specification --- and is declared using the syntax:
  321.  
  322.     void *ptr;
  323.  
  324. Indirection through a void pointer is not allowed; it must be
  325. cast to an appropriate pointer type first.
  326. Its main use is as a generic pointer.
  327.  
  328. Arrays with storage class auto may now be initialized.  If specified,
  329. the size of an array must be an integral expression greater than zero.
  330.  
  331. Special Modifiers
  332. -----------------
  333.  
  334. The Standard makes available the two attributes
  335. "const" and "volatile" for use as type modifiers.
  336.  
  337. An object declared to be "const" cannot be modified (assigned to,
  338. incremented or decremented) by a program.  Thus the following code
  339. is invalid:
  340.  
  341.     const int x;
  342.     /* ..... */
  343.     x = 2;        /* illegal! */
  344.  
  345. Initialization, however, is allowed:
  346.  
  347.     const unsigned char masks[] = { 0x00, 0xff };
  348.  
  349. A const object (if it is of static storage duration)
  350. may be data that is put into read-only memory.  Declaring such
  351. data with the const
  352. attribute allows the compiler to diagnose any attempts at
  353. modifying the data.  Function parameters may also be declared as
  354. const to indicate that they are not
  355. modified by the function.  This provides both extra documentation
  356. and, when function prototypes (described in Section 4) are used
  357. properly, consistent error-checking.
  358.  
  359. A "volatile" object is one that may be modified outside of program control.
  360. Memory-mapped I/O ports are a typical example.  Declaring an object as
  361. volatile indicates that the compiler should always generate code to
  362. fetch the object's value from its actual memory location ---
  363. it may have changed since the last access by the program.
  364. (This disallows optimizations which could load the value into
  365. a register and possibly return erroneous results.)
  366.  
  367.     volatile char *port1 = 0x00f3; /* ptr to I/O port */
  368.  
  369.     while( *port1 & DATA_FLAG ) /* needs to be volatile */
  370.         clear_io();
  371.  
  372. The const and volatile modifiers may be used (singly or together) in
  373. combination with any other valid type specifiers.
  374.  
  375. Pointers may also be declared to be const or volatile
  376. through the use of special syntax:
  377.  
  378.     int const *a;
  379.     int *const b;
  380.     int *const *c;
  381.  
  382. In the example "a" is declared to be a "pointer to a const integer",
  383. whereas "b" is declared to be a "const pointer to an integer".
  384. The distinction lies in the placement of the const attribute.  The
  385. declaration for "c" is even more confusing:  it declares a
  386. "pointer to a const pointer to an integer".
  387. Consider the following statements:
  388.  
  389.     a = NULL;  /* ok */
  390.     *a = 0;    /* error */
  391.     b = NULL;  /* error */
  392.     *b = 0;    /* ok */
  393.     c = &b;    /* ok */
  394.     *c = NULL; /* error */
  395.     **c = 0;   /* ok */
  396.  
  397. Because "a" is a pointer to a const int
  398. the value it points to may not be changed.  Similarly,
  399. because "b" is a const pointer to an int
  400. it may not be modified, though the value it points to may.
  401. The pointer "c" may be modified, but not the pointer "*c",
  402. though "**c" (an integer) is modifiable itself.
  403.  
  404. The volatile modifier may also be used with pointers
  405. in conjunction with or separate from const.
  406.  
  407. Bit-fields
  408. ----------
  409.  
  410. Bit-fields may now be of type int, unsigned int or signed int.
  411. Whether or not the high-order bit of an int
  412. bit-field is to be considered a sign bit is
  413. implementation-defined.
  414.  
  415. Vacuous Definitions
  416. -------------------
  417.  
  418. A vacuous definition consisting only of a struct or union
  419. specifier with a tag name is now allowed.  Its purpose is to
  420. hide any outer declaration of the same name in the current
  421. block, as the definitions for "struct a"
  422. demonstrate in this example:
  423.  
  424.     struct a
  425.       {
  426.        int x;
  427.       };
  428.  
  429.     int func()
  430.       {
  431.         struct a st1;  /* struct defined above */
  432.  
  433.         struct a;    /* vacuous definition:  it "clears"
  434.                         the current defn of struct a to
  435.                         make way for a new one */
  436.  
  437.         /* references to struct a now refer to the new
  438.            definition within this block */
  439.  
  440.         struct b
  441.           {
  442.             struct a *y;    /* refers to NEXT struct */
  443.           } st2;
  444.  
  445.         struct a
  446.           {
  447.             struct b *z;
  448.           } st3;
  449.  
  450.         st1.x = 1;
  451.         st2.y = &st3;       /* &st1 would give warning */
  452.         st3.z = &st2;
  453.       }
  454.  
  455.     /* old struct defn now back in scope */
  456.  
  457. Here the member "y" of "st2" is a pointer to the second "struct a",
  458. which is defined below it.  If the vacuous definition
  459.  
  460.     struct a;
  461.  
  462. had not been present, y would instead have been a pointer to the
  463. "struct a" defined in the previous (enclosing) scope level outside
  464. the function.
  465.  
  466. Conversions and Promotions
  467. --------------------------
  468.  
  469. The Standard defines the integral promotions as follows:  the
  470. char, short or bit-field types (with or without the signed or unsigned
  471. modifiers) may be used wherever an int is expected.  The values will be
  472. converted to int if possible; otherwise they will be converted to
  473. unsigned int.
  474.  
  475. The usual arithmetic conversions
  476. used with most binary operators have been modified to reflect
  477. the new types available to the programmer.
  478. Of particular note:  expressions of type float are not longer automatically
  479. converted to double for arithmetic purposes; such arithmetic may now be
  480. performed less accurately.
  481.  
  482. The Standard also specifies other rules regarding conversions.
  483. Where signed and unsigned integer values are concerned, the
  484. Standard now advocates value preserving as opposed to
  485. unsigned preserving rules:  unsigned values are promoted to
  486. signed int if possible, otherwise they are promoted to unsigned int.
  487. Floating-point values must now truncate towards zero when
  488. converted to integral types.  No rounding need occur when a
  489. double is demoted to float. Otherwise, the rules in K&R are unchanged.
  490.  
  491. Any program comparing or performing arithmetic on
  492. values of different types should be closely screened
  493. for possible changes in behaviour.
  494.  
  495.  
  496. Minimum Type Limits
  497. -------------------
  498.  
  499. Any compiler conforming to the Standard must also respect the
  500. following limits with respect to the range of values any
  501. particular type may accept.  Note that these are lower limits:
  502. an implementation is free to exceed any or all of these.
  503. Note also that the minimum range for a char is dependent
  504. on whether or not a char is considered to be signed or unsigned.
  505.  
  506.         Type                 Minimum Range
  507.  
  508.         signed char                 -127 to +127
  509.         unsigned char                  0 to 255
  510.         short int                 -32767 to +32767
  511.         unsigned short int             0 to 65535
  512.         int                       -32767 to +32767
  513.         unsigned int                   0 to 65535
  514.         long int             -2147483647 to +2147483647
  515.         unsigned long int              0 to 4294967295
  516.  
  517.         Type                 Minimum Precision
  518.  
  519.         float                      6 digits
  520.         double                    10 digits
  521.         long double               10 digits
  522.  
  523. The Standard also specifies that these limits should be present
  524. as preprocessor macros in the header file .id <limits.h>.
  525.  
  526. 3. Data Objects
  527. ---------------
  528.  
  529. Changes in this area have occurred mainly with respect to
  530. variable (object) linkage and initialization.
  531.  
  532. Initialization
  533. --------------
  534.  
  535. Objects declared as either "static" or "auto"
  536. may be initialized by following the declaration with an equals
  537. sign, '=', and an initialization expression.  External (inter-module)
  538. objects are discussed below in "Linkage".
  539.  
  540. If no initialization is given for a static
  541. object, all arithmetic types in the object are assigned 0 and all
  542. the pointers are set to NULL.  If no initialization is given to an
  543. auto
  544. object, its initial value is undefined.
  545. These rules are unchanged from K&R.
  546.  
  547. All initializers for either static objects or auto
  548. arrays, unions and structures must be constant expressions.
  549.  
  550. Unions may now be initialized: the initialization value is assigned
  551. to the first member of the union.
  552.  
  553. The initialization expression for a scalar (integral, floating-point
  554. or pointer) object may optionally be enclosed in braces.  Braces
  555. must enclose the initialization expressions for arrays, structures
  556. and unions.  There can be no more initializers in an initialization
  557. list than there are objects to be initialized (there may be less,
  558. though, and any remaining uninitialized objects are handled as
  559. described above).
  560.  
  561. An array of "char" or "pointer to char"
  562. may be initialized with a string constant.
  563.  
  564. Linkage
  565. -------
  566.  
  567. In this section object
  568. refers to an object declared outside of any function.
  569.  
  570. The linkage
  571. of an object determines its scope within the program.  An object
  572. with external linkage is known to all files in a program.  An object with
  573. internal linkage is known only to the file in which it is declared.
  574. Current C compilers
  575. often differentiate between the two in incompatible ways, an issue
  576. which the Standard resolves.
  577.  
  578. An object is said to be defined
  579. if it includes an initializer.  A defined object has internal
  580. linkage if the storage class static
  581. is specified; otherwise it has external linkage.  An object can
  582. only be defined once.
  583.  
  584. Any object declaration without the extern
  585. modifier and without an initializer
  586. constitutes what is known as a "tentative definition"
  587. of the object.  If an actual definition for the object is
  588. encountered in the same file, all tentative definitions are
  589. considered to be simple declarations referring to that object.
  590. Otherwise the first tentative definition is considered to be
  591. an actual definition with initializer equal to 0.
  592.  
  593.     /* example drawn from the Standard */
  594.  
  595.     int i1 = 1;         /* definition, external linkage */
  596.     static int i2 = 2;  /* definition, internal linkage */
  597.     extern int i3 = 3;  /* definition, external linkage */
  598.     int i4;             /* tentative definition */
  599.     static int i5;      /* tentative definition */
  600.  
  601.     int i1; /* tentative def., refers to previous */
  602.     int i2; /* invalid -- linkage disagreement */
  603.     int i3; /* tentative def., refers to previous */
  604.     int i4; /* tentative def., refers to previous */
  605.     int i5; /* invalid -- linkage disagreement */
  606.  
  607.     extern int i1;  /* these are all valid references */
  608.     extern int i2;
  609.     extern int i3;
  610.     extern int i4;
  611.     extern int i5;
  612.  
  613. These complex rules provide the most flexibility and allow
  614. the majority of current C code to be compatible with the
  615. Standard.
  616.  
  617. The simplest way to declare an externally-linked object is to
  618. define it in one file (with or without initializer) and reference
  619. it in all others through the use of an appropriate
  620. extern declaration.
  621.  
  622.  
  623. 4. Functions
  624. ------------
  625.  
  626. Additions to the language definition
  627. occur in the area of function declarations, function definitions
  628. and variable parameter lists.
  629.  
  630. Function Definitions
  631. --------------------
  632.  
  633. The Standard now allows the types of formal parameters to be
  634. specified within
  635. the actual function declaration at the start of the function
  636. definition.  This new-style definition form more closely
  637. resembles languages such as Pascal and Modula-2:
  638.  
  639.  
  640.     int main( int argc, char *argv[] )
  641.       {
  642.         /* ... */
  643.       }
  644.  
  645.  
  646. If this style is used, a type must be specified separately
  647. for each formal parameter in the argument list.  Mixing the
  648. new-style with the K&R-style in the same definition is not allowed.
  649.  
  650. This style is intended by ANSI to become the favored style,
  651. and a future Standard may disallow the K&R-style definition.
  652. For the moment, however, both styles may be used interchangeably.
  653.  
  654. Functions may also be defined as explicitly having no return
  655. values.  Such functions are called void functions
  656. and are defined using the type "void":
  657.  
  658.     void func( int a )
  659.       {
  660.         /* ... */
  661.         return;
  662.       }
  663.  
  664. Though the use of the return statement is allowed, such functions must not
  665. return an expression.  If no type is explicitly specified, the
  666. function still defaults to int to retain compatibility with K&R.
  667.  
  668. Function Declarations and Prototypes
  669. ------------------------------------
  670.  
  671. Function type declarations are also consistent with
  672. the new-style function definitions
  673. and may include a list of formal parameters.
  674. These parameters consist of type declarations with or without
  675. identifiers.  Identifiers are cosmetic only and need only be
  676. included for readability. Some examples are:
  677.  
  678.     int main( int, char *[] );
  679.     extern char *strcpy( char *dst, const char *src );
  680.  
  681. Note that declarations must be consistent as they will
  682. be checked by the compiler. Each declaration
  683. of a function should agree with all previous declarations
  684. in both the number and types of parameters.
  685.  
  686. The following declarations illustrate two special cases:
  687.  
  688.     extern int func1( void );
  689.     extern int func2();
  690.  
  691. The first case explicitly declares that the function func1
  692. does not take any parameters;  that the parameter list is
  693. empty or void.
  694.  
  695. The second declaration states that no information is known
  696. on the number and types of any formal parameter.
  697. This is to provide compatibility with K&R.
  698.  
  699. A function declaration that provides the number and types
  700. of parameters is called a function prototype.
  701. The addition of prototypes to C allows for stricter type-checking
  702. by the compiler.  When a prototype for a function has been declared,
  703. each subsequent call to that function is checked to make sure that
  704. the correct number of arguments has been supplied.  As well, the
  705. type of each argument is compared with what was declared
  706. in the prototype.  If different, the argument is converted to
  707. the required type as if it had been assigned to an object of that
  708. type.  The   default argument promotions
  709.  (char and short to int, float to double)
  710. are not performed when a prototype has been declared.
  711. (Note: The default argument promotions are separate from the
  712. usual arithmetic conversions.)
  713.  
  714. If a function prototype occurs in the same file as the
  715. definition of that function, both the prototype and the definition
  716. must agree exactly if the definition is of the new style.
  717. In K&R-style definitions, the formal parameters are first widened by the
  718. default argument promotions and then compared to the prototype(s).
  719. If no prototype occurs in the file, the function definition itself
  720. serves as a prototype for the code following it.
  721.  
  722. Variable Parameter Lists
  723. ------------------------
  724.  
  725. Certain C functions are designed to take a variable number of
  726. parameters.  Unfortunately, some compilers use different
  727. schemes for handling such situations and what works in one
  728. implementation may not work elsewhere.  The Standard therefore
  729. provides for the explicit declaration of such functions and
  730. portable facilities for handling them.  A function that takes a
  731. variable number of parameters is defined by ending the
  732. parameter list (new-style only) with an ellipsis:
  733.  
  734.     int printf( const char *format, ... )
  735.       {
  736.         /* ... */
  737.       }
  738.  
  739. Thus the only thing known about printf is that it takes
  740. at least one parameter, the type of which is a pointer to "const char".
  741. Prototypes may also be declared in this fashion:
  742.  
  743.     extern sprintf( char *dest, const char *format, ... );
  744.  
  745. The compiler will then make sure that each call to
  746. sprintf has at least two arguments, both of which are pointers to char.
  747.  
  748. The arguments themselves are accessed through the use of
  749. special macro facilities defined in the header file
  750. <stdarg.h>, part of the ANSI Standard Library.
  751.  
  752.  
  753. 5. The Preprocessor
  754. -------------------
  755.  
  756. The C preprocessor, long since recognized as an integral part
  757. of the language, has benefitted from a number of additions
  758. and clarifications in the Standard.
  759.  
  760. New Directives
  761. --------------
  762.  
  763. The #elif directive has been added as a shorthand form of the
  764. #else #if preprocessor sequence.
  765.  
  766. The identifier "defined" is reserved during an #if or #elif
  767. so that:
  768.  
  769.     #if defined( NULL )
  770.     #if !defined( TRUE )
  771.  
  772. are equivalent to:
  773.  
  774.     #ifdef NULL
  775.     #ifndef TRUE
  776.  
  777. Also new on the list are the directives
  778. #error and #pragma.
  779. The former produces an error message at compile-time; the latter
  780. is implementation-defined in its use and effects.
  781.  
  782. File Inclusion
  783. --------------
  784.  
  785. Besides the two allowable forms:
  786.  
  787.     #include <fname1>
  788.     #include "fname2"
  789.  
  790. a third form:
  791.  
  792.     #include fname3
  793.  
  794. is acceptable, provided that fname3
  795. is a macro which expands into one of the other two forms.
  796.  
  797. Macro Operators
  798. ---------------
  799.  
  800. Two new operators have been added for use within
  801. a macro replacement string.  The ## (concat)
  802. operator concatenates two adjacent preprocessor tokens (a
  803. preprocessor token is any consecutive series of non-blank
  804. characters).  The # (stringize)
  805. operator places the parameter following it in string form.
  806. For example, consider the following definition:
  807.  
  808.     #define debug( s )  printf( "x" # s "= %d\\n", x ## s )
  809.  
  810. The following macro call:
  811.  
  812.     debug( 1 );
  813.  
  814. expands to:
  815.  
  816.     printf( "x" "1" " = %d\\n", x1 );
  817.  
  818. which after string concatenation (see Section 7) gives the
  819. final result:
  820.  
  821.     printf( "x1 = %d\\n", x1 );
  822.  
  823. Program debugging through the use of macros has thus been
  824. made simpler.
  825.  
  826. Predefined Macros
  827. -----------------
  828.  
  829. Five new macros are predefined in the Standard, all of which are
  830. expanded to their appropriate values upon file compilation.
  831.  
  832.         Macro         Expands to
  833.         --------      -------------------
  834.  
  835.         __DATE__      current date
  836.         __TIME__      current time
  837.         __FILE__      current file name
  838.         __LINE__      current line number
  839.         __STDC__      non-zero value
  840.  
  841. The definition of __STDC__ indicates an ANSI-conformant compiler.
  842.  
  843. None of these macros may be redefined by a program.
  844.  
  845.  
  846. 6. The C Library
  847. ----------------
  848.  
  849. A standardized library of routines aids the programmer and
  850. enhances portability.  The Standard defines such a library,
  851. which is too large to describe here in any detail.  The
  852. Standard Library is based on the library compiled by
  853. /usr/group, a UNIX user's group, with all the UNIX dependencies deleted.
  854.  
  855. The Standard Library also provides a set of standard library
  856. headers.  These headers provide function prototypes for the
  857. set of routines that make up the library and define
  858. commonly-used macros.  As well, the functions
  859. and their prototypes have
  860. been changed so as to be invariant to the default promotions ---
  861. all are declared using promoted types (such as int and double)
  862. for parameters.
  863. Thus parameters passed to a library function will always be
  864. of the same type, regardless of whether a prototype is in
  865. scope or not.
  866.  
  867. Macros may also be defined in a header file to take the place
  868. of actual calls to library routines.  However, the library
  869. routines themselves must exist as the macros may be subjected
  870. to an #undef directive by the user at any time.
  871.  
  872. Among the most notable additions to the library are variable
  873. argument handling, numeric limits information, and
  874. locale (the current environment) information.
  875.  
  876. K&R library functions have also been converted to the new
  877. style and syntax, so that malloc, for example, now returns a
  878. "void *" as opposed to a "char *".
  879.  
  880. 7. Miscellaneous
  881. ----------------
  882.  
  883. Numerous other minor changes and additions have occurred throughout the
  884. language:
  885.  
  886.   * The escape characters '\a' and '\v' have been added for alarm (bell)
  887.     and vertical tab.
  888.  
  889.   * A series of special "trigraph characters"
  890.     has been added as equivalents to ASCII characters which may
  891.     not appear in the character sets of some countries; a trigraph
  892.     is a three-character sequence starting with "??":
  893.  
  894.                        Character        Trigraph
  895.  
  896.                            #              ??=
  897.                            [              ??(
  898.                            \              ??/
  899.                            ]              ??)
  900.                            ^              ??'
  901.                            {              ??<
  902.                            |              ??!
  903.                            }              ??>
  904.                            ~              ??-
  905.  
  906.   * The suffixes u and l may be used with integer constants to specify
  907.     unsigned and long values; both may be used together to specify
  908.     unsigned long.
  909.  
  910.   * The suffixes f and l may be used with floating-point constants to
  911.     specify float and long double values.
  912.  
  913.   * If the high bit of an octal or hex constant is set, it is
  914.     considered to be unsigned.
  915.  
  916.   * Adjacent strings separated only by white space are concatenated.
  917.  
  918.   * The unary plus ('+') has been added to force the evaluation
  919.     of an arithmetic expression to occur before any others.
  920.  
  921.   * A function can be called through a pointer using either the
  922.     K&R-style syntax (*fp)() or the new-style fp().
  923.  
  924.   * External identifier length significance is still 6 characters
  925.     with no case sensitivity (for compatibility with existing
  926.     linkers).
  927.  
  928.   * Internal identifier length significance is a minimum of 31
  929.     characters (case sensitive).
  930.  
  931.   * Each macro function call is expanded only once,
  932.     which prevents the definition of recursive macros.
  933.  
  934.   * External identifiers beginning with an underscore are
  935.     reserved for library usage.
  936.  
  937.   * Identifiers beginning with an underscore followed
  938.     either by a capital letter or another underscore
  939.     are reserved for use as predefined macro names.
  940.  
  941.   * Multi-byte character constants are allowed, though their
  942.     values are implementation-defined.
  943.  
  944.   * Hexadecimal character constants may be specified using
  945.     \x followed by a series of hexadecimal digits (ex.: '\xff')
  946.  
  947. Identifiers in current programs that are now reserved by
  948. the Standard will have to be altered to be portable
  949. across compilers.
  950.  
  951.  
  952. References
  953. ----------
  954.  
  955. American National Standards Institute, Inc.,
  956.     Draft Proposed American National Standard for Information Systems
  957.     - Programming Language C,
  958.     ANSI X3J11/87-221 (November 9, 1987).
  959.  
  960. American National Standards Institute, Inc.,
  961.     Rationale for
  962.     Draft Proposed American National Standard for Information Systems
  963.     - Programming Language C,
  964.     ANSI X3J11/87-219 (November 6, 1987).
  965.  
  966. Kernighan, Brian W., and Dennis M. Ritchie,
  967.     The C Programming Language,
  968.     Prentice-Hall, Englewood Cliffs, NJ (1978).
  969.  
  970. Plum, Thomas,
  971.     Notes on The Draft C Standard,
  972.     Plum Hall Inc., Cardiff, NJ (1987).
  973. --
  974. Eric Giguere                                       giguere@csg.UWaterloo.CA
  975.