简体   繁体   中英

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. 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? or maybe I'm lacking in searching skill...

All the run-time and standard libraries are written in 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. Linux glibc is obviously open source: 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. 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++. In fact, nearly the entire C++ Standard library has to be written in C++, because it's templated. 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.

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. Onmost operating systems this is done by generating a Software Interrupt using a special instruction ( SWI or SVC ) on arm. There is no equivalent for this in C or C++ and therefore assembler will be used. Assembler is also typically used to implement highly optimized memcpy , memmove , memcmp and other similar functions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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