R
R
RoflanDaniil2019-09-01 00:28:31
C++ / C#
RoflanDaniil, 2019-09-01 00:28:31

What is the C Runtime Library?

I can not find detailed information about what CRT is and why it is needed.
To make it easier and more specific, we will limit ourselves to Windows AND the C compiler that is in the studio.
As I understand from the information I have already read, CRT is a library that is implicitly compiled and linked with almost any program. It is needed in order to support the program during execution.
Some kind of layer of system calls. And I don't understand why this is necessary. Why is this layer needed?
Why doesn’t the compiler simply convert program functions like malloc and fopen into system calls, why do we need some kind of layer that you also need to carry with you, which is also not dynamic.
I also heard that you can even kind of write your own CRT for the program, if you really want to. How to do it and how does it work?
It would be interesting to look at a specific CRT implementation that is in the studio. Or in Gcc, where to look for it?
Do programs written in ASM need such a runtime library?
For example compiled MASM.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
pfemidi, 2019-09-01
@RoflanDaniil

Well , in Google on Wikipedia or something banned? CRT/RTL .
For assembler, this is not necessary, you do everything with your hands, yourself, for each processor and for each OS. And the C language is portable for the most part precisely because of the presence of the CRT. malloc and fopen are the same everywhere in C, but always different for a particular OS.
You can write your own CRT, but this is required quite rarely and for very specific and specific cases.
If it is interesting to look at a specific CRT implementation that is in the studio, then it comes with the studio in the form of source texts, at least look around.

R
res2001, 2019-09-01
@res2001

CRT is the implementation of the C/C++ standard library for this compiler.
OSes are usually written in C, and if there is no implementation of functions from the C standard in the OS, then they are implemented in the standard library. All classes from C++ stdlib are implemented in CRT.
CRT in VS can be linked both statically and dynamically, depending on the compiler options. If you link statically - your executable file swells, dynamically - the user must first install the appropriate vcredist (the installation can be built into your own installer). In terms of performance, both options are about the same.
You can not use the standard library in principle (by disabling it with compiler options) and work directly with the OS, but this imposes many restrictions and you are actually left with a castrated version of the PL, because for example, in C++, even the standard new/delete, as far as I know, is implemented in the standard library and there is no direct analogue in the OS. Usually, no one bothers with this because of problems that arise, the solution of which will significantly increase the time of project implementation, unless you need to make an executable file of the minimum size, start as quickly as possible and without dependencies.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question