Library function

Introduction

Generally refers to the functions provided by the compiler that can be called in the c source program. Can be divided into two categories, one is the library function specified by the C language standard, and the other is the library function specific to the compiler.

Due to copyright reasons, the source code of library functions is generally invisible, but you can see the introduction of its external interface library functions in the header file.

The C language statement is very simple. If you want to use the C language statement to directly calculate the sin or cos function, you need to write a rather complicated program. Because the C language statement does not provide a statement that directly calculates the sin or cos function. Another example is to display a paragraph of text, we can not find the display statement in the C language, we can only use the library function printf.

The library functions of the C language are not part of the C language itself. It is a set of programs compiled and provided by the compiler according to the needs of general users. The C library functions greatly facilitate users, and at the same time supplement the deficiencies of the C language itself. In fact, when writing C language programs, library functions should be used as much as possible, so that both the efficiency of the program and the quality of programming can be improved.

The static library is called here.

Basic concepts

Function library: The function library is a collection of functions with certain functions established by the system. The name of the function and the corresponding object code are stored in the library, as well as the relocation information required during the connection process. Users can also build their own user function library according to their needs.

Library functions: functions stored in the function library. Library functions have clear functions, entry call parameters and return values.

Link program: Link the object files generated by the compiler to generate an executable file.

Header files: Sometimes called include files. The data and variables to be used for information communication between C language library functions and user programs. When using a library function, you must embed (use #include) the header file corresponding to the function in the program.

Because there is no international standard for the function library that the C language compilation system should provide. Different versions of the C language have different library functions, and users should refer to the library function reference manual of the relevant version of C when using it. Let's take Turbo C? as an example to introduce the library functions of C, and some commonly used library functions of Turbo C are given in the appendix.

Nine categories

(1)I/O functions. Including various console I/O, buffered file I/O and UNIX-style unbuffered file I/O operations.

Required include file: stdio.h

For example: getchar, putchar, printf, scanf, fopen, fclose, fgetc, fgets, fprintf, fsacnf, fputc, fputs, fseek, fread, fwrite, etc.

(2) String, memory and character functions. Including functions for performing various operations on strings and performing operations on characters.

Required include files: string.h, mem.h, ctype.h, or string.h

For example: functions for checking characters: isalnum, isalpha, isdigit, islower , Isspace, etc. ? Functions for string manipulation: strcat, strchr, strcmp, strcpy, strlen, strstr, etc.

(3) Mathematical functions. Including various commonly used trigonometric functions, hyperbolic functions, exponential and logarithmic functions, etc.

Need include file: math.h

For example: sin, cos, exp (e to the power of x), log, sqrt (square root), pow (x of y Power) and so on.

(4) Time, date and system-related functions. Operation of time and date and setting of computer system status, etc.

Required include file: time.h

For example: time returns the time of the system; asctime returns the date and time in the form of a string.

(5) Dynamic storage allocation. Including the functions of "application for allocation" and "release" of memory space.

Required include files: alloc.h or stdlib.h

For example: calloc, free, malloc, realloc, etc.

(6) Directory management. Including functions for creating, querying, and changing the disk directory.

(7) Process control. Including the most basic process control functions.

(8) Character screen and graphic functions. Including various functions for drawing points, lines, circles, squares and coloring.

(9) Other functions.

Content

①The function of the function and the operations it can complete

②The number and order of the parameters, as well as the meaning and type of each parameter

③The meaning and type of the return value

④The include file to be used

This is a necessary condition for the correct use of library functions.

Related differences

(1) Library functions are part of the language or application program, while system calls are the interface provided by the kernel to the application program, and are part of the system

< p>(2) Library functions are executed in the user address space, system calls are executed in the kernel address space, library function running time belongs to user time, system calls belong to system time, library function overhead is small, and system call overhead is large

(3) Library functions are buffered, system calls are unbuffered

(4) System calls depend on the platform, library functions do not depend on

Built-in functions Library

1. The relationship between C language and C language library functions is similar to the relationship between Chinese characters and classic works. C language is a computer programming language, and C language function library is a document written in C language. It is convenient for latecomers to use the C language more simply and quickly.

2, C language is an introductory language for programming. Since the C language statement does not provide a statement to directly calculate the sin or cos function, it will cause difficulty in writing the program; but the function library provides the sin and cos functions, which can be used to directly call. To display a paragraph of text, we can't find the display statement in C language, we can only use the library function printf. The library functions of the C language are not part of the C language itself. It is a set of programs compiled and provided by the compiler according to the needs of general users. The C library functions greatly facilitate users, and at the same time supplement the deficiencies of the C language itself. When writing a C language program, using library functions can not only improve the operating efficiency of the program, but also improve the quality of programming.

Related Articles
TOP