Runtime System

This page was translated by a robot.

A runtime system has the task of supporting the final program at runtime, i.e. during the actual execution. A runtime system basically regulates everything that the programmer has not already explicitly defined in the code. Thus, a programmer cannot address or control the runtime system directly, but only trust that it supports the program in an appropriate manner.

Details

Basically, the runtime system supports the program at runtime. However, when it comes to a precise definition of the word runtime systemgoes, the spirits separate. The author had trouble bringing the content presented here to a common denominator. Some sources claim that C has no runtime support at all and C++ only has cobbled together and barely usable runtime support. Here, however, the view is maintained (at the author's discretion) that anything that requires additional time and memory overhead besides the code written by the programmer belongs to the runtime system. However, the boundaries between language support (any additional work required to implement the code) and runtime support are blurred. The functionality of a runtime system is roughly divided here into implicit codes and meta-commands

Implizite Codes

Implicit codes are bits and bytes that the compiler inserts implicitly (without the programmer having to do anything) or arranges them in such a way that the program can run. Basically, in C and C++, the statements that are written in the source code are translated directly into assembler code. However, this alone is not enough to get a program running. Since source code is usually divided into several parts, the individual code fragments make no sense and must be made executable by means of additional machine code and clever arrangement. In some sources, implicit codes are not considered run-time support because these codes can be specified at compile time. Here on this page, however, they are listed with a focus on the supporting character.

The statements of a program are usually in several functions, which have to be called at certain points with the correct arguments. Programmers simply write function calls in the source code, but the compiler and linker must create implicit code for such calls that performs exactly the desired argument passing and jump to the correct address.

The polymorphism supported in C++ also belongs to the category of implicit codes. When a polymorphic object is called, the dynamic type of the object is implicitly used to address methods of the referenced object. This is done by cleverly breaking down the method references in the stored object. This ordering is implicit in C++.

C++ also supports the determination of type information at runtime (the so-called RTTI: RunTime Type Information ). Here, an additional type indicator is implicitly stored for each object that was declared using a class with virtual methods. This makes it possible to dynamically determine the type of any variable. This is required for the dynamic_cast<>operator as well as for the typeidoperator . Since RTTI are rarely used, today's compilers turn them off by default, but they are automatically enabled when necessary. This information is used in C++ for exception handlingonly possible with polymorphic classes. Note: Polymorphism, always available in C++, does not require RTTI.

Depending on the point of view, further examples of implicit codes can be listed. In the context of this C/C++ reference, however, this category is closed with the above-mentioned most important representatives.

Meta-Befehle

A programmer simply cannot know certain things while writing the program. For example, he does not know what kind of computer the program will possibly run on, which and how much memory is available to him or what other processes are running. Meta-commands stand above the program and communicate with the operating system, which allows them to offer higher-level functionalities to the program flow. Meta-commands define complex code, often hidden behind a standard library function or operator along with implicit global variables and a call to an operating system procedure. The actual programming of each meta command is operating system and compiler dependent.

A very important operation in C and C++ is memory allocation and deallocation. In C there are the malloc and free functions for this, in C++ the new and delete operators. Even if functions are explicitly mentioned in the case of mallocand , they ultimately have the task of requesting memory from the operating system or of implementing this operating system functionality themselves. The request must be made using operating system-specific methods without the programmer or the program being aware of it. The address of memory returned by the - or - operation cannot be predicted before actual run time.freenewdeletemallocnew.

An operating system must be able, for example, to abort a program if necessary, to put it to sleep, to wake it up again or to report expired countdowns. This is achieved by means of so-called signals , which immediately interrupt the normal program flow and execute a code that matches the signal sent. A programmer has the ability to control and utilize this signal processing. In order for this asynchronous and thus unpredictable communication with the operating system to be possible, there are corresponding implementations of the signal commands, which are ultimately also to be understood as meta commands.

The input and output functions for files, devices, sockets, pipes, etc. belong in the same category. Although all the necessary functions are available in the standard libraries, their programming differs per system and compiler.

It should be noted that not all standard library functions are to be considered meta-commands. Again, other examples of meta-commands could be listed, but for this C/C++ reference, the above should suffice.

Final Remark

Although the runtime system in C and C++ is essential for the survival of many programs, it plays a subordinate role in everyday programming, it is simply there and does its job. Other programming languages ​​sometimes have much more developed runtime systems, which are increasingly becoming a main part of programming and thus have a much greater influence on a programmer's design decisions. It should be noted that some programmers appreciate the language C++ and especially C, precisely because the runtime system does not constantly radio in, i.e. the level of support is limited and the programmer still has full control over the program as expected of a command language.

Next Chapter: Memory, Heap, Stack, Loader