Libraries Introduction

A library is a collection of (usually related) precompiled functions.

These functions can be either an interface to the operating system, or fast and efficient implementations of frequently needed tasks. The latter save the programmer the time and effort of writing such functions.

The run time library is essential for implementing things which are not provided for by the language - such as input/output. Since, I/O and related actions (e.g. asking the computer what time it is) are machine and operating system dependent, these library functions provide a more or less portable means for carrying out such tasks.

Not all libraries are common to all operating systems. But there is a common set which has been identified. Operating system specific library functions are still a great help. They can make it almost entirely unnecessary to use machine language. Use of such library functions is of course not portable, but at least if they do not already exist on another machine, or compiler or operating system, then it is still usually possible to write your own functions to bridge the gap.

If you find that there are a set of functions that you use frequently, then you can create your own additional library. Most environments provide, or one can purchase, the software tools to create and modify your libraries.

To use a library, two things are needed. First, the library file, "*.lib", which consists of one or more compiled functions in object form. Second, a corresponding header file, "*.h", which contains the prototypes for the functions, plus any external global variable declarations, and manifest constants (using the #define preprocessor directive), and lastly, any typedefs and struct or union definitions.

It might be instructive to read some of the header files for the commonly used libraries, such as and .

The library groupings will be listed and described below, but first a list of only those functions which have been specified in the ANSI 'C' standard will be listed by name. If you want as portable a program as possible, with respect to library functions you must restrict your self to these functions and must write any others yourself.

The ANSI 'C' standard library functions are:

  abort    difftime  frexp     isupper    putc     sscanf     system
  abs      div       fscanf    isxdigit   putchar  strcat     tan
  acos     exit      fseek     labs       puts     strchr     tanh
  asctime  exp       fsetpos   ldexp      qsort    strcmp     tempnam
  asin     fabs      ftell     ldiv       raise    strcpy     tmpfile
  assert   fclose    fwrite    localtime  rand     strcspn    tolower
  atan     feof      getc      log        realloc  strerror   toupper
  atan2    ferror    getchar   log10      remove   strlen     ungetc
  atexit   fflush    getenv    longjmp    rename   strncat    va_arg
  atof     fgetc     gets      malloc     rewind   strncmp    va_end
  atoi     fgetpos   gmtime    memchr     scanf    strncpy    va_start
  atol     floor     isalnum   memcmp     setbuf   strpbrk    vfprintf
  bsearch  fmod      isalpha   memcpy     setjmp   strrchr    vprintf
  calloc   fopen     iscntrl   memmove    setvbuf  strspn     vsprintf
  ceil     fprintf   isdigit   memset     signal   strstr
  clearerr fputc     isgraph   mktime     sin      _strtime
  clock    fputs     islower   modf       sinh     strtod
  cos      fread     isprint   perror     sprintf  strtok
  cosh     free      ispunct   pow        sqrt     strtol
  ctime    freopen   isspace   printf     srand    strtoul

Some of the functions named in the above list plus others not in the list, are not truly functions. They are actually macros, that is, they are implemented in the appropriate header file with the #define preprocessor directive.

Some of these macros may not behave as expected if the arguments use the pre or post decrement (--) or increment (++) operators as those will be evaluated multiple times. And of course you can not take a pointer to a function of it is a macro. Lastly, there is no type checking with a macro as there is with a function prototype.

In some cases besides the macro, e.g. toupper(), there is also a corresponding function, in this case: _toupper().

Note that functions which have a variable number of arguments, such as printf() and scanf(), indicated by ellipses, three periods (...), in the prototype cannot possibly have the compiler do type checking for the parameters implied by the ellipses. This is because the compiler is not expected to know how the function knows what type to expect - it varies with every such function.

We will now classify most of the functions and indicate which header file contains their prototypes or macro definitions and related declarations. These categories will include functions which go beyond those minimum required by the ANSI 'C' specification.

It is beyond the scope of this tutorial to describe every single function in detail. Only an overall description will be given with the list of function (or macro) names. To find out the details of any particular function, as well as which header file it is in, consult your 'C' library reference manual.

Note that some functions have their prototypes in more than one header file.

It is important to understand that including a header file in your source file does not include or cause the functions whose prototypes are given to become part of your program. It is using, i.e. calling, those functions that causes them to be part of your program.

The list given below is not complete - not even of the ANSI standard libraries. The header files and contents not covered vary from operating system to operating system and compiler to compiler.

The header files to be discussed are:

        header file    category
        -----------    ------------------------------------------------
        limits.h       constants specifying ranges of integral types
        memory.h       buffer manipulation
        string.h       string manipulation
        ctype.h        character classification and conversion
        stdio.h        stream I/O
        io.h           low level I/O
        conio.h        console and port I/O
        math.h         mathematical functions
        float.h        constants specifying ranges of floating types
        malloc.h       memory allocation
        direct.h       directory management and searching
        process.h      process control
        time.h         time, (see also: sys/timeb.h)
        stdlib.h       data conversion and miscellaneous
        errno.h        system-level call error values and variables

© 1991-2008 Prem Sobel. All Rights Reserved.