# C语言

**C**是一种通用编程语言，1969年至1973年间诞生于贝尔电话实验室，是作为初生的Unix操作系统的系统实现语言而创造的。它经由[肯·汤普森](https://www.edgepedia.org/zh/ken-thompson)（Ken Thompson）的B语言从无类型的BCPL语言衍生而来，在[丹尼斯·里奇](https://www.edgepedia.org/zh/dennis-ritchie)（Dennis Ritchie）手中获得了类型结构——里奇保留了B语言的大部分语法，同时添加了类型并编写了第一个编译器<sup>[1](https://www.nokia.com/bell-labs/about/dennis-m-ritchie/chist.html)</sup>。里奇对结果的总结很平实：“C古怪、有缺陷，却取得了巨大的成功”<sup>[1](https://www.nokia.com/bell-labs/about/dennis-m-ritchie/chist.html)</sup>。

| 关键事实 | 详情 |
|---|---|
| 诞生 | 1969–1973年于贝尔实验室，与早期Unix同步开发；最具创造性的时期是1972年<sup>[1](https://www.nokia.com/bell-labs/about/dennis-m-ritchie/chist.html)</sup> |
| 创造者 | 丹尼斯·M·里奇（Dennis M. Ritchie），1971–73年间将汤普森的B语言改造为C，并编写了第一个编译器<sup>[1](https://www.nokia.com/bell-labs/about/dennis-m-ritchie/chist.html)</sup> |
| 谱系 | BCPL（马丁·理查兹）→ B（肯·汤普森，1969–70）→ C<sup>[1](https://www.nokia.com/bell-labs/about/dennis-m-ritchie/chist.html)</sup> |
| 奠基之作 | 《C程序设计语言》（克尼汉与里奇，1978），人称“白皮书”或“K&R”，在此后数年间充当了语言的定义<sup>[1](https://www.nokia.com/bell-labs/about/dennis-m-ritchie/chist.html)</sup> |
| 标准化 | ANSI X3J11委员会于1983年启动工作；现行标准为C23，即ISO/IEC 9899:2024，由ISO和IEC于2024年采纳<sup>[1](https://www.nokia.com/bell-labs/about/dennis-m-ritchie/chist.html)</sup><sup> • </sup><sup>[2](https://open-std.org/jtc1/sc22/wg14/)</sup> |
| 原始平台 | 为DEC PDP-11上的UNIX操作系统设计并实现<sup>[3](https://archive.computerhistory.org/resources/access/text/2024/05/102734492-05-0001-acc.pdf)</sup> |
| 实现类别 | 宿主式实现提供完整的标准库；独立式实现（如操作系统内核）只需少量头文件<sup>[4](https://gcc.sourceware.org/onlinedocs/gcc-14.1.0/gcc/Standards.html)</sup> |

## 贝尔实验室的起源

20世纪60年代末，贝尔电话实验室的计算机系统研究正处于动荡时期，C语言正是从这一环境中直接生长出来的<sup>[1](https://www.nokia.com/bell-labs/about/dennis-m-ritchie/chist.html)</sup>。肯·汤普森于1969–70年创造了B语言，直接源自马丁·理查兹（Martin Richards）的BCPL。丹尼斯·里奇是[贝尔实验室](https://www.edgepedia.org/zh/bell-labs)计算科学研究部的研究员，1968年获哈佛大学数学博士学位，他在1971–73年间将B语言改造为C<sup>[1](https://www.nokia.com/bell-labs/about/dennis-m-ritchie/chist.html)</sup><sup> • </sup><sup>[5](https://computerhistory.org/profile/dennis-ritchie/)</sup>。从1972年到1977年，关于这门语言的提案来自里奇、艾伦·斯奈德（Alan Snyder）、史蒂文·C·约翰逊（Steven C. Johnson）、迈克尔·莱斯克（Michael Lesk）和汤普森，而约翰逊为可移植性而构建的编译器则长期被广泛使用。<sup>[1](https://www.nokia.com/bell-labs/about/dennis-m-ritchie/chist.html)</sup>

这门语言是在一台小型机器上创造的，是改善贫瘠编程环境的工具，最初并未以可移植性为首要目标。然而它成功地在从最小的个人计算机到超级计算机的各种机器上表达了程序，包括操作系统<sup>[1](https://www.nokia.com/bell-labs/about/dennis-m-ritchie/chist.html)</sup>。

## C与Unix

C和Unix是一起发展起来的。K&R的前言指出，C最初是为DEC PDP-11上的UNIX操作系统设计并实现的，而该操作系统、C编译器以及几乎所有Unix应用程序都是用C编写的<sup>[3](https://archive.computerhistory.org/resources/access/text/2024/05/102734492-05-0001-acc.pdf)</sup>。贝尔实验室的一份历史记录指出，几乎整个Unix操作系统及其相关的实用程序和命令程序都是用C编写的，而该语言的效率和可读性极大地促成了Unix系统的成功<sup>[6](https://archive.computerhistory.org/resources/access/text/2022/08/102804421-05-01-acc.pdf)</sup>。

可移植性很快随之而来。[IBM System/370](https://www.edgepedia.org/zh/ibm-system-370)、Honeywell 6000和Interdata 8/32上都有了生产级编译器，该书前言指出C不依附于任何特定的硬件或系统<sup>[3](https://archive.computerhistory.org/resources/access/text/2024/05/102734492-05-0001-acc.pdf)</sup>。第二波语言变革在1977年至1979年间达到高峰，当时正在展示Unix系统的可移植性<sup>[1](https://www.nokia.com/bell-labs/about/dennis-m-ritchie/chist.html)</sup>。

工具链随语言一同成长。为了鼓励关注官方语言规则、检测合法但可疑的构造、发现简单分离编译无法察觉的接口不匹配，史蒂夫·约翰逊（Steve Johnson）改造了他的pcc编译器以生成lint，后者扫描一组文件并对可疑构造提出意见<sup>[1](https://www.nokia.com/bell-labs/about/dennis-m-ritchie/chist.html)</sup>。

## K&R之书与标准化

1978年，[布莱恩·克尼汉](https://www.edgepedia.org/zh/brian-kernighan)（Brian Kernighan）和里奇出版了《C程序设计语言》，这是该语言第一部广泛可得的描述，在此后数年间充当了事实上的定义<sup>[1](https://www.nokia.com/bell-labs/about/dennis-m-ritchie/chist.html)</sup>。前言将C描述为具有“表达的经济性、现代的控制流和数据结构，以及丰富的运算符集合”，既不是“非常高级”的语言，也不是大型语言，然而因其不受限制和通用性而便于完成许多任务<sup>[3](https://archive.computerhistory.org/resources/access/text/2024/05/102734492-05-0001-acc.pdf)</sup>。

从1983年起，ANSI X3J11委员会对该语言进行了标准化，产生了[ANSI C](https://www.edgepedia.org/zh/ansi-c)标准（X3.159-1989）<sup>[1](https://www.nokia.com/bell-labs/about/dennis-m-ritchie/chist.html)</sup>。标准化今天仍在ISO/IEC JTC1/SC22/WG14——C语言的国际标准化工作组——的主持下继续<sup>[2](https://open-std.org/jtc1/sc22/wg14/)</sup>。后续版本相继推出：第五版C23（ISO/IEC 9899:2024）取消并取代了第四版（ISO/IEC 9899:2018）<sup>[7](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3220.pdf)</sup>。

## 标准的结构

ISO标准规定了C程序的形式和解释，旨在促进在各种计算系统上的可移植性、可靠性、可维护性和高效执行；它并非设计为教程<sup>[7](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3220.pdf)</sup>。它定义了两类符合标准的实现。宿主式实现支持整个标准，包括所有库设施，程序通过`int main (void)`或`int main (int, char *[])`启动。独立式实现是所有实现都必须提供的，它可以缺少除最小头文件集之外的库设施，这些头文件如`<float.h>`、`<limits.h>`、`<stdarg.h>`和`<stddef.h>`；操作系统内核是独立式程序的标准范例<sup>[4](https://gcc.sourceware.org/onlinedocs/gcc-14.1.0/gcc/Standards.html)</sup>。

## C23与当前发展

C23是当前版本，添加了大量语言特性，包括十进制浮点类型（`_Decimal32`、`_Decimal64`、`_Decimal128`）、位精确整数（`_BitInt`）、二进制整数字面量、数字分隔符、空初始化器`={}`、属性如`[[deprecated]]`和`[[nodiscard]]`、函数定义中的无名参数、单参数`_Static_assert`，以及`static_assert`和`thread_local`关键字<sup>[8](https://en.cppreference.com/c/23)</sup>。它还引入了`nullptr`常量及其类型`nullptr_t`，提议逐步淘汰旧的`NULL`宏，并让空指针常量拥有自己的类型而非整数类型<sup>[9](https://open-std.org/jtc1/sc22/wg14/www/docs/n2978.htm)</sup>。C23还要求有符号整数采用二进制补码表示，从而消除了早期原码和反码允许的负零整数值的可能性<sup>[10](https://open-std.org/jtc1/sc22/wg14/www/docs/n2643.htm)</sup>。

C23周期结束后，下一个规划版本的工作于1月24日开始，称为“C2y”<sup>[7](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3220.pdf)</sup>。

## 未定义行为与安全工具

未定义行为是C和C++的惯用特征：它是指使用语言未对其施加要求的错误程序构造，例如整数溢出<sup>[11](https://arxiv.org/abs/2606.12064)</sup>。C标准指出了由无效指针操作引起未定义行为的不同情形，包括在数组对象之外或刚好越过其末尾形成指针、解引用尾后指针，以及越界数组下标，例如对声明为`int a[4][5]`的数组使用`a[1][7]`<sup>[12](https://wiki.sei.cmu.edu/confluence/spaces/c/pages/87152322/ARR30-C.%2BDo%2Bnot%2Bform%2Bor%2Buse%2Bout-of-bounds%2Bpointers%2Bor%2Barray%2Bsubscripts)</sup>。

基于编译器的工具在运行时检测这些错误。AddressSanitizer是一个快速的内存错误检测器，将编译器插桩与运行时库相结合，可捕获堆、栈和全局变量的越界访问、释放后使用、返回后使用、作用域结束后使用、重复释放、无效释放和内存泄漏，运行时间通常约为原来的2倍<sup>[13](https://clang.llvm.org/docs/AddressSanitizer.html)</sup>。Clang还提供ThreadSanitizer用于数据竞争、MemorySanitizer用于未初始化读取，以及UndefinedBehaviorSanitizer用于一组快速、兼容的未定义行为检查<sup>[14](https://clang.llvm.org/docs/UsersManual.html)</sup>。

## 遗产

里奇一直留在贝尔实验室，直到2007年退休，于2011年10月12日去世。他与肯·汤普森因共同创造Unix和开发C语言，于1983年获得ACM图灵奖，1999年获得美国国家技术奖章，2011年获得[日本国际奖](https://www.edgepedia.org/zh/japan-prize)<sup>[5](https://computerhistory.org/profile/dennis-ritchie/)</sup>。[计算机历史博物馆](https://www.edgepedia.org/zh/computer-history-museum)记载，C及其衍生语言继续被用于编写让数字设备和网络运转的软件<sup>[5](https://computerhistory.org/profile/dennis-ritchie/)</sup>。

## References

1. [Dennis M. Ritchie, "The Development of the C Language" (HOPL-II, 1993), Bell Labs](https://www.nokia.com/bell-labs/about/dennis-m-ritchie/chist.html)
2. [ISO/IEC JTC1/SC22/WG14 – C, official working group page](https://open-std.org/jtc1/sc22/wg14/)
3. [Kernighan & Ritchie, *The C Programming Language*, preface (Computer History Museum scan)](https://archive.computerhistory.org/resources/access/text/2024/05/102734492-05-0001-acc.pdf)
4. [Standards, Using the GNU Compiler Collection (GCC)](https://gcc.sourceware.org/onlinedocs/gcc-14.1.0/gcc/Standards.html)
5. [Dennis Ritchie, Computer History Museum profile](https://computerhistory.org/profile/dennis-ritchie/)
6. [A history of computing at Bell Telephone Laboratories (1937–1975), 1982](https://archive.computerhistory.org/resources/access/text/2022/08/102804421-05-01-acc.pdf)
7. [ISO/IEC 9899:2024 (C23), N3220 working draft, WG14](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3220.pdf)
8. [C23, cppreference.com](https://en.cppreference.com/c/23)
9. [N2978: Introduce the nullptr constant, WG14](https://open-std.org/jtc1/sc22/wg14/www/docs/n2978.htm)
10. [N2643: two's complement requirement, WG14](https://open-std.org/jtc1/sc22/wg14/www/docs/n2643.htm)
11. [Undefined Behavior in C and C++: An Experiment With Desktop Use Cases, arXiv](https://arxiv.org/abs/2606.12064)
12. [ARR30-C. Do not form or use out-of-bounds pointers or array subscripts, SEI CERT C Coding Standard](https://wiki.sei.cmu.edu/confluence/spaces/c/pages/87152322/ARR30-C.%2BDo%2Bnot%2Bform%2Bor%2Buse%2Bout-of-bounds%2Bpointers%2Bor%2Barray%2Bsubscripts)
13. [AddressSanitizer, Clang documentation](https://clang.llvm.org/docs/AddressSanitizer.html)
14. [Clang Compiler User's Manual](https://clang.llvm.org/docs/UsersManual.html)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 30, 2026; Oct 15, 2026 · Edited: Sep 30, 2026; Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Programming languages › Individual programming languages › C-family and imperative languages

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/the-c-programming-language

English original: https://www.edgepedia.org/the-c-programming-language
