简体   繁体   English

C 和 C++ 标准库是用什么语言编写的? 他们的源代码在哪里?

[英]In what languages are the C and C++ standard libraries written? Where is their source code?

I always wonder what language was the C/C++ runtime and standard library written in. At first I thought it is a casual C/C++ language, but to be able to talks with the machine I doubt C/C++ is enough.我一直想知道 C/C++ 运行时和标准库是用什么语言编写的。起初我以为它是一种随意的 C/C++ 语言,但要能够与机器对话,我怀疑 C/C++ 是否足够。 Therefore, I think it may be assembly language instead.因此,我认为它可能是汇编语言。 If it is either C/C++ or asm language, then why don't I really see source codes flying around?如果是 C/C++ 或 asm 语言,那为什么我真的看不到源代码飞来飞去? or maybe I'm lacking in searching skill...或者我可能缺乏搜索技巧......

All the run-time and standard libraries are written in C/C++.所有运行时和标准库都是用 C/C++ 编写的。 Most vendors ship the source code.大多数供应商都提供源代码。

They are usually written in C with some assembly mixed in. Visual Studio ships with big chunks of source code for CRT (C RunTime) if not all of it.它们通常用 C 编写,并混入一些程序集。Visual Studio 附带大量用于 CRT(C 运行时)的源代码,如果不是全部的话。 Linux glibc is obviously open source: http://ftp.gnu.org/gnu/glibc/ Linux glibc 显然是开源的: http://ftp.gnu.org/gnu/glibc/

They are typically written in their host language, interoperating with the operating system API to obtain things that can't be obtained natively.它们通常用它们的宿主语言编写,与操作系统 API 互操作以获得本地无法获得的东西。 Many features are written in pure language- for example, the containers & algorithms section of the C++ Standard library pretty much has to be written in C++.许多功能都是用纯语言编写的——例如,C++ 标准库的容器和算法部分几乎必须用 C++ 编写。 In fact, nearly the entire C++ Standard library has to be written in C++, because it's templated.事实上,几乎整个 C++ 标准库都必须用 C++ 编写,因为它是模板化的。 I don't know why you haven't found any source- the Microsoft CRT source is available to any dev, I think, I've certainly seen questions on here posting the CRT source, and the GNU libc++ is open source, I'm pretty sure.我不知道你为什么没有找到任何源代码——微软 CRT 源代码可供任何开发人员使用,我想,我肯定在这里看到了关于发布 CRT 源代码的问题,而且 GNU libc++ 是开源的,我我很确定。

Most of the runtime is written in C or C++ but there is an important exception and that is the code that calls into the kernel.大多数运行时都是用 C 或 C++ 编写的,但有一个重要的例外,那就是调用 kernel 的代码。 Onmost operating systems this is done by generating a Software Interrupt using a special instruction ( SWI or SVC ) on arm.在大多数操作系统上,这是通过在 arm 上使用特殊指令( SWISVC )生成软件中断来完成的。 There is no equivalent for this in C or C++ and therefore assembler will be used.在 C 或 C++ 中没有等效项,因此将使用汇编程序。 Assembler is also typically used to implement highly optimized memcpy , memmove , memcmp and other similar functions.汇编器也通常用于实现高度优化的memcpymemmovememcmp和其他类似功能。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM