1 / 10

21. THE STANDARD LIBRARY

21. THE STANDARD LIBRARY. General Rules. • The C standard library is divided into 15 parts (24 in C99), with each part described by a header.

arlene
Download Presentation

21. THE STANDARD LIBRARY

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 21. THE STANDARD LIBRARY

  2. General Rules • The C standard library is divided into 15 parts (24 in C99), with each part described by a header. • The names of functions, types, and macros defined in a header are reserved; programs that include the header shouldn’t use these names for any other purpose. • Identifiers with external linkage (for example, function names) are always reserved, even if the header isn’t included.

  3. C89 Headers • <assert.h> Diagnostics. Contains only the assert macro, which enables programs to perform self-checks. If any check fails, the program terminates. #include <assert.h> void assert(int expression); /* if expression is false, writes a diagnostic message and terminates execution */

  4. C89 Headers • <ctype.h> Character Handling. Provides functions for testing and converting characters. #include <ctype.h> int islower(int c); /* is c a lower-case letter? */ int tolower(int c); /* if c is an upper-case letter, returns the lower-caseversion; otherwise, returns c unchanged */

  5. C89 Headers • <errno.h> Errors. Provides macros that allow the program to detect whether an error has occurred during calls of certain library functions. errno (which may be a macro or a variable) is an lvalue of type int that is set to a positive value when an error occurs. #include <errno.h> #define errno … • <float.h> Characteristics of Floating Types. Provides macros that define the range and accuracy of floating types. #include <float.h> #define FLT_DIG 6 /* digits of precision */ #define FLT_MAX 3.402823466e+38 /* largest floating number */

  6. C99 Headers • C99 supports all the headers of C89 and adds nine more. Most of the new headers deal with specialized mathematical needs or provide support for internationalization. • • C99 also adds functions to many of the C89 headers. In particular, a number of mathematical functions have been added to <math.h>.

  7. C99 Headers • New headers in C99: <complex.h> Complex Arithmetic. Provides support for doing arithmetic on complex and imaginary numbers. <fenv.h> Floating-Point Environment. Provides access to floating-point status flags and control modes. Testing status flags allows a program to determine more information about floating-point exceptions. Changing a control mode (how rounding is done, for example) gives a program more control over how floating-point arithmetic is performed. <inttypes.h> Format Conversion of Integer Types. Provides functions for manipulating greatest-width integers and converting numeric character strings to greatest-width integers.

  8. C99 Headers <iso646.h> Alternative Spellings. Provides macros that can be used in place of certain operators. For example, the and macro is equivalent to the && operator. <stdbool.h> Boolean Type and Values. Defines the bool, true, and false macros. <stdint.h> Integer Types. Provides integer types having specified widths. For example, int8_t is a signed integer type with exactly 8 bits, and uint8_t is an unsigned integer type with 8 bits.

  9. C99 Headers <tgmath.h> Type-Generic Math. Provides parameterized macros that represent functions in <math.h> and <complex.h>. A call of one of these macros is expanded into a call of the corresponding function, based on the types of the argument(s). <wchar.h> Extended Multibyte and Wide Character Utilities. Defines the wchar_t type (among others) and provides functions for working with multibyte characters and wide characters. These include input and output functions, wide string manipulation functions, and functions that convert between multibyte and wide character sequences.

  10. C99 Headers <wctype.h> Wide Character Classification and Mapping Utilities. Provides functions for classifying wide characters and converting their case.

More Related