简体   繁体   English

我在哪里可以看到C ++标准库中使用的代码?

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

When I compile a program with #include 当我使用#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? 对所有人开放还是不向公众开放?

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 . 这是GNU的libstdc++文档(和源代码)(它带有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 从以下镜像之一下载源代码: http//gcc.gnu.org/mirrors.html

Generally the #included file is readable, but the library it implements is generally not readable. 通常,#include文件是可读的,但它实现的库通常是不可读的。 The include files on a mac are in /usr/include/c++ . mac上的include文件位于/ usr / include / c ++中

The library code depends on the compiler. 库代码取决于编译器。 For Gnu C++ used in linux and Mac you can definitely see the code. 对于在Linux和Mac中使用的Gnu C ++,你绝对可以看到代码。 You might have to download it. 您可能需要下载它。 It is available at http://gcc.gnu.org/libstdc++/ 它可以在http://gcc.gnu.org/libstdc++/上找到

I don't think Windows C++ library code is available. 我认为Windows C ++库代码不可用。

It depends on what toolchain you are using, not every vendor is making his implementation public. 这取决于您使用的工具链,并非每个供应商都将其实施公开。 You can have a look at the GNU C library for starters: http://www.gnu.org/software/libc/ 你可以看一下GNU C库的初学者: http//www.gnu.org/software/libc/

Dinkumware , the company behind the C++ standard template library that is used in Visual Studio for example, is offering a commercial product, thus the code is not available to everyone - it really depends on your license. 例如,在Visual Studio中使用的C ++标准模板库背后的公司Dinkumware正在提供商业产品,因此代码并非每个人都可以使用 - 这实际上取决于您的许可证。 Some versions of Visual Studio indeed ship with the source code of the runtime included. 某些版本的Visual Studio确实附带了运行时的源代码。

As for the STL, there is also STLport , an open source STL implementation. 至于STL,还有STLport ,一种开源STL实现。

Your best bet will indeed be the projects that gcc/g++ depend on. 你最好的选择确实是gcc / g ++所依赖的项目。

The C++ standard itself is just this: a standard. C ++标准本身就是这样一个标准。 The implementation of which is done by many vendors. 其实施由许多供应商完成。 STLport and GNU libstdc++ are both open source and can be looked at as a whole. STLport和GNU libstdc ++都是开源的,可以作为一个整体来看待。 Visual Studio ships with Dinkumware C++ standard library. Visual Studio附带Dinkumware C ++标准库。 It is closed source. 它是封闭源。

Nevertheless, you can always see the source of the headers by opening the include directory of your C++ standard lib. 不过,您始终可以通过打开C ++标准库的include目录来查看标头的来源。 The files are named just like you include them. 这些文件的命名就像包含它们一样。 Much of it is implemented in headers anyway. 其中大部分都是在标题中实现的。 But are pretty much unreadable to the untrained eye. 但是对于未经训练的眼睛来说几乎是不可读的。

But when it comes to using the C++ library don't depend on the exact source code of it, but rather on what the C++ standard says. 但是,当涉及到使用C ++库时,不依赖于它的确切源代码,而是依赖于C ++标准所说的内容。 Don't program to an implementation, but rather to the standard. 不要编程实现,而是编程。

Run this command from your command line: 从命令行运行此命令:

find /usr -name iostream

That will tell you the directory you want. 这会告诉你你想要的目录。

If you use something like Visual Studio, you can put a break point and then start line-by-line stepping through your code and it will open the included files as you go along. 如果你使用像Visual Studio这样的东西,你可以设置一个断点,然后逐行逐步执行代码,它将随你打开包含的文件。 Quickest way into a file in my opinion. 在我看来,最快的方式进入文件。 Otherwise you can find the code somewhere on your PC ... on mine its in C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VC\\crt\\src\\ostream for example, replacing ostream with iostream, sstream, etc (note that those are file names without extensions) but also if you look at the directory you'll see a lot of .h and .c files 否则,您可以在PC上的某处找到代码...在我的C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VC\\crt\\src\\ostream ,例如,用iostream,sstream等替换ostream(请注意,那些文件名没有扩展名)但是如果你查看目录,你会看到很多.h和.c文件

All system headers ship with your compiler. 所有系统头都随编译器一起提供。 On Linux systems, these can normally be found under /usr/include . 在Linux系统上,通常可以在/usr/include下找到它们。 On other platforms, the will normally live where you installed the compiler. 在其他平台上,通常会存在安装编译器的位置。

Commercial libraries do not normally ship source code. 商业图书馆通常不提供源代码。 On linux, these can normally be found in the source pacakges. 在linux上,这些通常可以在源pacakges中找到。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有没有一个地方我们可以看到PHP &lt;=&gt; C ++ equilavent库/函数为一个从C ++开始的php开发人员? - Is there a place where we can see PHP <=> C++ equilavent libraries/function for a php developer starting with C++? C 和 C++ 标准库是用什么语言编写的? 他们的源代码在哪里? - In what languages are the C and C++ standard libraries written? Where is their source code? 在哪里可以看到C ++字符串函数c_str的代码 - Where can I see code for the C++ String function c_str C ++标准库与凡人制作代码+我在哪里可以找到来源? - C++ standard library vs mortal made code + where can I find the sources? 在哪里可以将源代码下载到GNU C ++标准库? - Where can I download the source code to the GNU C++ Standard Library? 在哪里可以找到标准的 Visual C++ 头文件? - Where can I find the standard Visual C++ header files? 在ELF文件中的什么地方,我可以看到c ++中变形的名称 - where in ELF file i can see the mangled names in c++ 在Linux上编译C ++代码。 需要使用gcc / 4.7.2。 找不到标准库 - Compiling C++ code on Linux. Need to use gcc/4.7.2. Can't locate standard libraries 从ASM调用的C ++代码中的标准库的链接 - Linkage of standard libraries in C++ code called from ASM VS Code无法检测到标准C ++库 - VS Code unable to detect Standard C++ Libraries
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM