Reputation: 1114
Could someone say me where I can found the source file where are the definitions of the standard libraries?
For example, where is the file string.c
that contains the definitions of the function prototyped in string.h
? And above all, it exists?
Upvotes: 1
Views: 272
Reputation: 101506
You're probably not going to like this.
The C++ Standard does not say specifically where anything in the Standard Libraries are actually implemented. It says where things are declared, but only to the degree that it names the file(s) you must #include
in order to bring the names in. For example, the Standard says that:
std::string
is a typedef
for basic_string<...>
, and in order to bring that typedef
in to your program, you must #include <string>
. It doesn't actually say that basic_string
or string
are defined in <string>
however, and it doesn't say where, on your hard drive <string>
is even located. In fact, it's often not in <string>
in the real world. In my implementation, (MSVC10) string
is defined in a different file, <xstring>
, and it looks like this:
typedef basic_string<char, char_traits<char>, allocator<char> >
string;
Useful, huh?
There's another aspect. A lot of the stuff in the Standard Library is template stuff, like string
, so because of the way templates work in C++ these facilities must be so-called "include libraries." But not everything in the Standard Library is made up of templates.
Consider sprintf
. The Standard says that this declaration is provided by #include <cstdio>
but that, like string
isn't even where it's declared. And sprintf
isn't a template thing. the implementation is in what's often called the CRT -- the C Runtime Library. This is a collection of DLLs and LIBs (in MSVC10, anyway) that your program links to to run code like sprintf
.
Now the bad news is those components that are in the CRT are generally shipped without source code. You don't know where sprintf
is implemented and you can't look at the source code. You're left with little alternative in these cases except get a job with MicroSoft so you can take a look at the source code. :)
Upvotes: 2
Reputation: 6578
For GCC, which is open source, you can download the sources for the libstdc++ library from their mirror sites here. Included in the download is the source for the std library. Bear in mind that different vendors will have different implementations, so the link provided is merely how the developers of GCC decided to implement the standard library
Upvotes: 3
Reputation: 5724
its all in compilled state, some of maybe optimized by asm. You need find sources of your compiler to see definitions
Upvotes: 3