How to Understand C run-time Library (C Runtime Library)

Source: Internet
Author: User
Note: The following content is based on the posts discussed in csnd and compiled based on your understanding. For reference only.

1) The Runtime Library is the c run-time library, which is the concept of the C language rather than the C ++ language World: The name is because the functions in these libraries are required when your C program is running.

2) C is a so-called "Small kernel" language, which is small in itself (not many keywords, program flow control, data type, etc.). Therefore, after the C-language kernel is developed, Dennis Ritchie and Brian kernighan use C to rewrite more than 90% of UNIX system functions and separate the most commonly used functions, the header file and the corresponding library are formed in this way in C run-time library.

3) subsequently, with the prevalence of the C language, the C compiler manufacturers/individuals/groups all follow the old tradition and have corresponding standard libraries on different platforms, however, most implementations are related to various platforms. Since each C compiler has many differences and subtle differences in C support and understanding, it has ansi c; ansi c (subjective intention) it defines in detail the specific meaning of each element of the C language and the implementation requirements of the compiler, introduces a new function declaration method, and sets up the standard form of the standard library. Therefore, the C Runtime Library is provided by the compiler manufacturer. The header files and library functions provided by other vendors/individuals/groups should be called the third-party C Runtime Library (Third Party C run-time libraries ).

4) C run-time library contains initialization code and error handling code (such as divide by zero ). The program you write can run without the math library, but cannot handle complex mathematical operations. However, without the C run-time library, main () won't be called, exit () cannot be responded. Because the C run-time library contains the most basic and commonly used functions for C program running.

5) in the C ++ world, there is another concept: Standard C ++ library, which includes the C run-time library and STL mentioned above. The reason for including C run-time library is obvious. c ++ is the superset of C, and there is no reason to re-create a C ++ run-time library. the standard C ++ Library added by VC for C ++ mainly includes libcp. lib, libcpmt. lib and msvcprt. lib

6) in windows, the C run-time library provided by VC is divided into dynamic Runtime Library and static Runtime Library.
The dynamic Runtime Library is mainly the dll library file msvcrt. dll (or msvcrtd. DLL for debug build), and the corresponding import library file is msvcrt. Lib (msvcrtd. Lib for debug build)
The main files corresponding to the static Runtime Library (release version) are:
Libc. Lib (single thread static library, retail version)
Libcmt. Lib (multithread static library, retail version)

Msvcrt. dll provides thousands of C functions. Even low-level functions such as printf are in msvcrt. dll. In fact, most of the time your program runs in these runtime libraries. When your program (release version) is compiled, VC Automatically releases the corresponding Runtime Library file (libc) based on your compilation options (single thread, multi-thread, or DLL. lib, libcmt. lib or import library msvcrt. lib.

Which C run-time library is connected to your program during compilation depends on the Compilation options:
/MD,/ml,/mt,/LD (use run-time Library)
In VC, you can use the following method to set which C run-time library to join your program:
To find these options in the development environment, click Settings on the project menu. then click the C/C ++ tab, and click code generation in the category box. see the use run-time library drop-down box.

Considering program portability, if both functions can complete a function, select the Runtime library function, because the C compiler manufacturers provide unified support for the Standard C run-time library.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.