C Runtime Library and C language function library/Microsoft C Runtime Library

Source: Internet
Author: User
Tags microsoft c

1. Is the C Runtime Library the same thing as the C function library (such as stdio. h and stdlib. h?

2. In the technical reference books, I often say "Microsoft C Runtime Library". Is the C Runtime Library a language database or an operating system database? Do other operating systems, such as Unix/Linux, have C Runtime libraries?

3. Why do I need to use both the Win32 API and the C Runtime Library? Can the former replace the latter?

4. Is tchar. h and wchar. h The header file of the C Runtime library or the header file of the API? Which of the following macros are defined for tchar, wchar, _ text, and text?

 

Resend)

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.



Comment on this article
Han012 (2001-09-03)
I am very glad that many netizens have participated in the discussion and raised different points of view in this article. I would like to express my gratitude for this.
In addition, I think it is necessary to add some comments to some netizens:

1) In Windows, dynamic C run-time library is available only after VC ++ 4.0 (if I remember correctly) is used for static C run-time library. the dynamic C run-time library is provided in DLL format. theoretically, both static and dynamic C run-time libraries are compiled binary code that can be run. therefore, theoretically, as long as the call rules are met, "different compilation systems on the same operating system platform should be able to share library files ". In this regard, I agree with pingpingpangpang. Just as I have not mentioned in this article that "C run-time library" can only be used by C/C ++ ."

2) although theoretically, the C run-time library can be shared by other compilation systems, it must be admitted that the C run-time library is more closely related to the C language. this is like making clothes. The C run-time library is customized for C language. Others may wear it, but the size may not be suitable. historically, ansi c has developed a standard form of C standard library (including function names, calling rules, parameters, and so on) for the C language ). even if other languages can be used, the calling rules of C run-time library must be exclusive. in addition, the following code calls the C run-time library function fopen and printf most naturally and directly. Although I am not familiar with Pascal, Fortran, but I believe that if they want to call the C run-time library functions fopen and printf, I am afraid they will do more work.

File * stream;
......
If (Stream = fopen ("data", "R") = NULL)
Printf ("the file 'data' was not opened/N ");
Else
Printf ("the file 'data' was opened/N ");
......

3) in windows, when an application is loaded, perform the following steps (for part of the description, ignore the serial number and only refer to the description that contains the C Runtime Library ):

......
6. The main thread calls the _ dllmaincrtstartu () function for each DLL.
When a DLL is linked, the linker embeds the DLL entry/exit function address in the generated DLL file image. By default, the linker assumes that the function name is _ dllmaincrtstartup. This function is included in the C run-time Library (C Runtime Library) file.
When the DLL file is mapped to the process address space, the system actually calls the _ dllmaincrtstartup function instead of your dllmain function. Execute this function:
A. initialize the C run-time Library (C Runtime Library ).
// Do runtime startup initializers.
_ Initterm (<__ xi_a, <__ xi_z );
......

7. The main thread executes winmaincrtstartup/(maincrtstartup) based on the subsystem value GUI/(Cui) in the EXE file)
A. Get the pointer of all the command lines of a new process.
B. Get the environment variable pointer of a new process.
C. Use stdlib. h to initialize the global variables of the C run-time Library (C Runtime Library) that can be accessed by the application. For example
_ Osver, _ winmajor, _ winminor, _ winver, _ argc, _ argv, _ Environ.
// Do runtime startup initializers.
_ Initterm (_ xi_a, _ xi_z );
......

Therefore, C run-time Library (C Runtime Library) does contain its own initialization code for C run-time library, such as initializing C run-time Library (C Runtime Library) global Variable _ argc, _ argv, _ Environ. I don't know if these global variables can be called in Pascal or fortran programs.

For reference only

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.