A brief introduction to the area of writing C/C ++ applications, the role of the standard library, and how it is implemented in various operating systems. I’ve been around C++ for a while now, and one of the things that puzzled me at first was its internals: where did the kernel functions and classes I used come from? Who invented them? Are they packaged up somewhere in my system? Is there an official C ++ manual? In this article, I will attempt to answer these questions by moving from the nature of C and C ++ languages to practical implementations.

How are C and C++ formulated

When we talk about C and C++, we really mean a set of rules that define what a language should do, how it should behave, and what functionality it should provide. C/C++ compilers must follow these rules and generate binary applications in order to process C/C++ written source code. It sounds very close to HTML: browsers follow a set of instructions, so they can render a web page in an unambiguous way. As with HTML, the rules of C and C++ are theoretical. A large group of people from the International Organization for Standardization (ISO) meets several times a year to discuss and define language rules. Yes, C and C++ are standardized things. They all end up with an official book called The Standard, which you can buy from their website. Papers will be released as the language evolves, defining a new standard each time. This is why we have different versions of C and C++ : C99, C11, C++03, C++11, C++14, etc. The numbers correspond to the year of publication/release.

These standards are very detailed and technically new documentation: I wouldn’t consider them manuals. It is usually divided into two parts:

1.C/C++ functions and features;

2.C/C++ API– a collection of classes, functions, and macros that developers can use in their C/C++ programs. It is also known as the standard library.

For example, here’s an extract from the first part of the C library that defines the structure of the main function:

1. The definition of main, the function called when the program starts.

Here is another excerpt from the same standard describing the Fmin function, a member of CAPI:

2. Define min functions in math.h stolen files.

As you can see, there’s very little code involved. Someone has to read the standard and translate it into something a computer can digest. This is what people do with the compiler, a tool that reads and processes C and C ++ source files, and the implementation that converts the standard library into code. Let’s take a closer look.

The C standard library

The C standard library, also known as the ISO C library, is a collection of macros, types, and functions for performing tasks such as input/output processing, string manipulation, memory management, mathematical computation, and many other operating system services. It is defined in the C standard, such as the C11 standard. The content is distributed in different header files, such as math.h I mentioned above.

C + + standard library

Similar to the C standard library concept, but only for C ++. The C++ standard library is a set of C++ template classes that provide generic programming data structures and functions such as linked lists, heaps, arrays, algorithms, iterators, and any other C++ component you can think of. The C++ library also contains the C library and is defined in the C++ standard (for example, the C++ 11 standard).

Implement the C/C++ standard library

This is where we get to the actual code. Developers working on library implementations read the official ISO specification and translate it into code. They must rely on the functionality provided by their operating system (read/write files, allocate memory, create threads,……) All of these are called system calls), so each platform has its own library implementation. Sometimes it’s part of the system kernel, and sometimes it’s an add-on – a compiler – that must be downloaded separately.

GNU/Linux version

The GNU C library, also known as glibc, is the GNU project implementation of the C standard library. Not all standard C functions can be found in glibc: most mathematical functions are actually implemented in the libm library, which is a separate library.

As of today, glibc is the most widely used C library on Linux. However, for a time during the 1990s, Glibc had a competitor called Linux LIBC (or liBC for short), which was produced by a branch of Glibc 1.x. For some time, Linux LIBC was the standard C library in many Linux distributions. Over the years, Glibc turned out to be superior to Linux LIBC, and all Linux distributions that used it switched back to Glibc. So if you find a file on your disk called libc.so.6, don’t worry: it’s the modern version of Glibc. To avoid confusion with previous Linux liBC versions, the version number was increased to 6 (they couldn’t name it glibc.so.6: all Linux libraries must start with a lib prefix). The C++ standard library, on the other hand, is implemented in libstdc++ or the GNU standard C++ library. This is an ongoing project to implement the standard C++ library on GNU/Linux. In general, all regular Linux distributions use libstdc++ by default.

Mac and iOS version implementation

On Mac and iOS, the C standard library is implemented as part of libSystem, the core library located in /usr/lib/libsystem.dylib. LibSystem contains other components, such as math libraries, threading libraries, and other low-level utilities.

For the C++ standard library, libstdc++ was the default option on macs prior to OS X Mavericks (V10.9). This is the same implementation that can be found on modern Linux-based systems. Since OS X Mavericks, Apple has switched to using libc++, a replacement for the GNU libstdc++ standard library introduced by the LLVM project, the Mac’s official compiler framework. IOS developers can access the standard library using the IOS SDK (Software Development Kit), a set of tools that allow the creation of mobile applications.

The Windows version of the implementation

On Windows, the implementation of the standard library has been strictly limited to Visual Studio, Microsoft’s official compiler. They are commonly called the C/C++ Runtime Library (CRT), and it covers both C/C++ implementations. In the beginning, CRT was implemented as the crtdll. DLL library (I guess there was no C++ standard library available at the time). Starting with Windows 95, Microsoft began migrating it to MSVCRT [version number].dll (msvcr20.dll, msvcr70.dll, etc.), presumably including the C++ standard library as well. As recently as 1997, they decided to simplify file names to msvcrt.dll, which unfortunately led to a nasty DLL mess. That’s why, starting with Visual Studio 7.0, they switched back to using separate DLLS for each release.

Other Translations (1)

Visual Studio 2015 introduces deep CRT refactoring. The implementation of the C/C ++ standard library was migrated to a new library, the Universal C runtime library (Universal CRT or UCRT), compiled as UCrtBase.dll. UCRT is now available as part of the Windows group starting with Windows 10.

The Android version of the implementation

Bionic is an implementation of the C standard library written by Google for its Android operating system, which is used directly underneath. Third-party developers can access Bionic through the Android Native Development Kit (NDK), a tool set that allows you to write Android applications using C and C++ code.

On the C++ side, the NDK provides many implementations:

  • Libc++, the official android operating system from Lollipop onwards, and modern Mac operating systems use it as a C++ standard library. As of the NDK release 17, it will be the only C++ standard library implementation available in the NDK;

  • Gnustl, an alias for libstdc++, which are the same library on GNU/ Linux. This library is deprecated and will be removed in NDK release 18;

  • STLport, a third-party implementation of the C++ standard library written by the STLport project, has been inactive since 2008. Like GnuSTl, STLport will be removed in NDK release 18.