现代C
Modern C

原始链接: https://gustedt.gitlabpages.inria.fr/modern-c/

现代C语言的新版本已发布,恰逢即将发布的ISO C23标准。本次更新包含大量改动,主要集中在整数方面。关键新增内容包括位精确类型,例如`_BitInt(N)`,新的库头文件``用于溢出检查算术运算,以及``用于位操作,并可能支持128位类型。枚举类型也得到了改进。 C23引入了`nullptr`常量、属性注解、使用`auto`和`typeof`增强的类型泛型编程、使用`{}`对变长数组进行默认初始化,以及任何类型的命名常量的`constexpr`等概念。 新版本还涵盖了复合表达式、lambda表达式、国际化和全面的程序故障处理。新的附录和临时包含头文件有助于在现有平台上更平滑地过渡到C23,从而能够立即采用新的标准。

Hacker News 上的一篇帖子讨论了“现代C语言 (inria.fr)”,引发了关于C语言发展方向的辩论。一些评论员对`auto`和`constexpr`等潜在的新特性表示兴奋。另一些人则批评这种趋势,认为“现代C语言”试图模仿C++,但却并没有完全采用其核心概念,而是选择了诸如`_Generic`之类的不太优雅的解决方案。一些人欣赏现有的“现代C语言”资源,例如Jens Gustedt的书,但更倾向于坚持使用C99等较旧的C语言标准。帖子里分享了INRIA文档的PDF下载链接。讨论中还出现了轻松愉快的交流,引用了David Bowie的歌曲“Modern Love”,用户们互相询问这首歌是否能让你准时到达教堂,以及其他歌词。

原文

The free version of this new edition is now available at

This new edition has been the occasion to overhaul the presentation in many places, but its main purpose is the update to the new C standard, C23. The goal was to publish this new edition of Modern C at the same time as the new C standard goes through the procedure of ISO publication. The closest approximation of the contents of the new standard in a publically available document can be found here. New releases of major compilers already implement most of the new features that it brings.

Among the most noticeable changes and additions that we handle are those for integers: there are new bit-precise types coined _BitInt(N), new C library headers <stdckdint.h> (for arithmetic with overflow check) and <stdbit.h> (for bit manipulation), possibilities for 128 bit types on modern architectures, and substantial improvements for enumeration types. Other new concepts in C23 include a nullptr constant and its underlying type, syntactic annotation with attributes, more tools for type generic programming such as type inference with auto and typeof, default initialization with {}, even for variable length arrays, and constexpr for name constants of any type. Furthermore, new material has been added, discussing compound expressions and lambdas, so-called “internationalization”, a comprehensive approach for program failure.

Also added has been an appendix and a temporary include header for an easy transition to C23 on existing platforms, that will allow you to start off with C23 right away.


联系我们 contact @ memedata.com