Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I find implementations of the C++ Standard Library? [duplicate]

I'm curious about learning how certain C++ features work. I'm trying to learn C++11 concepts such as std::function, but I keep hitting walls like INVOKE(function, arguments, return) that I don't understand. People tell me, "Oh, just ignore it and use auto" but I want to have a truly deep understanding of how C++ and its standard library works, so I wanted to find the source code of the standard library.

I would guess that the C++ Standard Library is somewhat related with the C Standard Library and the messy assembly/binary implementations at the lowest level for stuff like std::iostream and such, but I'm interested in more higher-level abstractions like smart pointers and std::function. Given that many of the C++11 libraries were once Boost ones, how might I find the source for C++ Standard Library implementations?

like image 426
Cinch Avatar asked Mar 16 '15 06:03

Cinch


People also ask

Who implements C++ Standard Library?

The two most popular open source implementations of standard C++ library are: libstdc++, part of gcc project. libc++, part of LLVM project.

Where can I find C library?

Libaries consist of a set of related functions to perform a common task; for example, the standard C library, 'libc. a', is automatically linked into your programs by the “gcc” compiler and can be found at /usr/lib/libc. a. Standard system libraries are usually found in /lib and /usr/lib/ directories.

Which function is known as the standard library function?

C Standard library functions or simply C Library functions are inbuilt functions in C programming. The prototype and data definitions of these functions are present in their respective header files. To use these functions we need to include the header file in our program.


2 Answers

The two most popular open source implementations of standard C++ library are:

  • libstdc++, part of gcc project
  • libc++, part of LLVM project

Both websites contain links to git/svn repositories with source code.

like image 67
el.pescado - нет войне Avatar answered Sep 19 '22 13:09

el.pescado - нет войне


You might dive into the source code of libstdc++ if you care about GCC. Indeed it sometimes leverages above the standard C library (e.g. ::operator new might call malloc, etc...)

Notice that since the C++ library is part of the standard, some of it might be implemented in a compiler specific way.

In principle, nothing requires standard headers to be real operating-system files; a compiler could parse #include <vector> in a particular way not involving any file. I know no compiler doing that much!

In particular, libstdc++ is using some GCC builtins and some GCC attributes (which happens to be also understood by Clang/LLVM).

And some standard types require (or profit from) internal support in the compiler. For example, GCC has some specific code to deal with va_list and with std::initializer_list (and of course basic types like int...), etc. Also, the compiler's implementation of C++ closures (or lambda functions) is related to other classes, etc...

Also, some optimization passes of GCC (it has several hundreds of them) are designed with some features of libstdc++ implementation in mind.

BTW, using a recent gdb debugger with e.g. the libstdc++6-4.9-dbg debian package might also help.

like image 41
Basile Starynkevitch Avatar answered Sep 22 '22 13:09

Basile Starynkevitch