So I have been trying to understand what exactly is the C runtime, and had to go in depth while building my own kernel.
What I've understood is that you don't need a C runtime to build every C program (as is the case of a kernel). Also, the runtime provides an interface between the C program and the kernel. Here are my questions:
So what exactly does the runtime do ?
Does it only act as this interface (so that if we implement it ourselves, we don't need the runtime), or it has some other functions as well ?
Does the runtime link in any files when a program is compiled ?
Are common functions like printf
or scanf
a part of the runtime or the C library ? What kind of functions would be provided by the runtime ?
EDIT: I have referred to What is the C runtime library?, but it doesn't answer my questions. What I have asked is not being addressed there.
user1619508 :
I'm going to answer the question from a different perspective, that of a bare-metal embedded system with no operating system. There are two important functions that are performed by the c runtime in this case:\n\n\nUninitialized static variables are given a value of zero (the bss section)\nExplicitly initialized static variables get their intitial value\n\n\nThose are the minimum responsibilities of the C runtime, although there may be other processor-dependent initialization functions. After performing these tasks the runtime just branches to the main function. I haven't checked to see if crt1.o initializes variables but I would assume that it does...my C runtime is just a short assembly program.",
2014-05-02T15:27:33