为什么使用Linux内核codeD非标准C(GCC特定功能)? [英] Why is linux kernel coded using non-standard C (gcc specific features)?

查看:126
本文介绍了为什么使用Linux内核codeD非标准C(GCC特定功能)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Linux内核code使用的声明-EX pression和typeof运算扩展,使它只在GCC编译。

Linux kernel code uses "statement-expression" and typeof extension that makes it only compilable under gcc.

更多我想它,它越没有意义。

More I think about it, more it doesn't make sense.

这违背了便携性和标准C的目的
(现在的linux内核code需要与支持GCC的扩展特定的编译器)。

It defeats the purpose of portability and standard C. (now linux kernel code needs a specific compiler that supports gcc extensions).

是不是一个糟糕的设计选择,或在那里制作Linux内核code比与gcc特殊原因?

Was it a bad design choice or was there a specific reason for making linux kernel code specific to gcc?

编辑:当我说这违背了便携性,我用它在不同的上下文中。我在想,由符合标准的C,它会被接受,支持标准C(这正是创建标准的目的 - 统一所有C不同的方言)的编译器,因此是更加便于携带。当然,由于GCC是如此受欢迎,和gcc支持数不胜数的架构,这条线几乎是毫无意义的。我只是询问是否有背后的不符合标准的C特定的理由。

When I said it defeats portability, I used it in different context. I was thinking, by conforming to standard C, it would be accepted to ANY compiler that supports standard C (which is exactly the purpose of creating a standard -- to unify all different dialects of C), hence being more portable. Of course, since gcc is so popular, and gcc supports zillion architectures, this line is almost meaningless. I am just asking if there was a specific rationale behind not conforming to standard C.

推荐答案

为什么Linux内核开发者担心使得上说,微软的Visual Studio编译器或IBM编译了xlC其code的工作?

Why would the Linux kernel developers worry about making their code work on say Microsoft Visual Studio compiler or the IBM xlC compilers?

当你写一个内核,你需要非常precise控制了很多东西,比如详细的内存布局,比你在用户空间做(一般)。这样的控制是不是真的占C标准(左如例如实现定义的特性),所以要么一些扩展是必要的,或者你需要依靠编译器的怪癖。

When you're writing a kernel, you need very precise control over a lot more stuff, like exact memory layout, than you do (generally) in userspace. Such controls are not really accounted for in the C standard (left as implementation defined characteristics for instance), so either some extensions are necessary, or you need to rely on the compiler's quirks.

与一个特定的编译器坚持,利用其扩展的优势,是一个理性的决定。的code并不需要是便携式的跨编译器 - 它需要是在不同的硬件平台的高效和便携

Sticking with one specific compiler, taking advantage of its extensions, is a rational decision. The code doesn't need to be portable across compilers - it needs to be efficient and portable across different hardware platforms.

这篇关于为什么使用Linux内核codeD非标准C(GCC特定功能)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆