有哪些可用的 GNU C 扩展在 C99 中实现起来并不简单?
为什么Linux内核只能用GCC编译?哪些 GNU C 扩展对于某些项目来说确实是必要的,为什么?
How come the Linux kernel can compile only with GCC? What GNU C extensions are really necessary for some projects and why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
以下是 Linux 内核使用的几个 gcc 扩展:
这里还有一些: http://www.ibm.com/developerworks/linux/library/l-gcc-hacks/
许多 gcc 细节都非常依赖于体系结构,或者由于 gcc 的实现方式而成为可能,并且由 C 标准指定可能没有意义。其他只是对 C 的方便扩展。由于 Linux 内核是为了依赖这些扩展而构建的,因此其他编译器必须提供与 gcc 相同的扩展才能构建内核。
这并不是说 Linux必须依赖 gcc 的这些功能,例如 NetBSD 内核很少依赖 gcc 特定的东西。
Here's a couple gcc extensions the Linux kernel uses:
Here's a few more: http://www.ibm.com/developerworks/linux/library/l-gcc-hacks/
Much of these gcc specifics are very architecture dependent, or is made possible because of how gcc is implemented, and probably do not make sense to be specified by a C standard. Others are just convenient extensions to C. As the Linux kernel is built to rely on these extensions, other compilers have to provide the same extensions as gcc to be able to build the kernel.
It's not that Linux had to rely on these features of gcc, e.g. the NetBSD kernel relies very little on gcc specific stuff.
GCC 支持 嵌套函数,这不是 C99 标准的一部分。也就是说,需要进行一些分析才能了解它们在 Linux 内核中的实际流行程度。
GCC supports Nested Functions, which are not part of the C99 standard. That said, some analysis is required to see how prevalent they actually are within the linux kernel.
Linux 内核是为了由 GCC 编译而编写的,因此标准合规性从来都不是内核开发人员的目标。
如果 GCC 提供了一些有用的扩展,使编码更容易或编译内核更小或更快,那么使用这些扩展就是一个自然的选择。
Linux kernel was written to be compiled by GCC, so standard compliance was never an objective for kernel developers.
And if GCC offers some useful extensions that make coding easier or compiled kernel smaller or faster, it was a natural choice to use these extensions.
我想它们并不是真的那么必要。只是有很多有用的东西,而且交叉编译器的可移植性对于 Linux 内核来说并不是一个放弃这些细节的问题。更不用说摆脱对扩展的依赖需要大量的工作。
I guess it's not they are really that necessary. Just there are many useful ones and cross-compiler portability is not that much an issue for Linux kernel to forgo the niceties. Not to mention sheer amount of work it would take to get rid of relying on extensions.