Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where can I see the code used in C++ standard libraries?

Tags:

c++

macos

When I compile a program with #include

where can I see the contents of that file, and also since that file contains declarations, where can I see the actual code used in those functions?

Is it open to everyone or is it not available to the public?

like image 691
fmunshi Avatar asked Nov 14 '10 00:11

fmunshi


People also ask

Where is C standard library stored?

In Unix-like systems, the traditional place for the basic system libraries is /lib/ , with many additional libraries are found in /usr/lib/ , sometimes in sub-directories. Furthermore, locally built libraries are traditionally placed in /usr/local/lib/ .

Where can I see C++ source code?

You should already have the sources in your compiler installation. If you are using an IDE with a "jump to include file" command, select any STL header and jump to it. If you are using some kind of UNIX, look in /usr/include/c++ . See where that STL header includes other headers and recurse :v) .

What is library code in C?

A library in C is a collection of header files, exposed for use by other programs. The library therefore consists of an interface expressed in a . h file (named the "header") and an implementation expressed in a . c file.

What is included in standard C library?

The C standard library provides macros, type definitions and functions for tasks such as string handling, mathematical computations, input/output processing, memory management, and several other operating system services.


2 Answers

The actual code is in the platform-specific standard libraries that come with your compiler, you can see it by looking at the standard library implementation source.

Here's the documentation (and source) for libstdc++ by GNU (it comes with gcc): http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/index.html.

Download the source from one of these mirrors: http://gcc.gnu.org/mirrors.html

like image 192
David Titarenco Avatar answered Oct 14 '22 19:10

David Titarenco


Generally the #included file is readable, but the library it implements is generally not readable. The include files on a mac are in /usr/include/c++.

The library code depends on the compiler. For Gnu C++ used in linux and Mac you can definitely see the code. You might have to download it. It is available at http://gcc.gnu.org/libstdc++/

I don't think Windows C++ library code is available.

like image 33
John Smith Avatar answered Oct 14 '22 18:10

John Smith