standard C (gcc specific features)?

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.

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

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

EDIT: 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.


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

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.

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.


Here's some good background on the specific extensions used. It's not really written from the perspective of "why?", but it should give you some good background on the reasons for choosing this approach:

http://www.ibm.com/developerworks/linux/library/l-gcc-hacks/


The Linux Kernel code is a complicated piece of software. The more facilities gcc provides them with, they happier the coders would be.

Why would they care about portability? gcc compiles code under virtually every hardware configuration PLUS it provides them with good features. Why would they care if Linux could or could not be compiled with another compiler?

Today, portable code is such a common concept for us that we believe it should be existent everywhere. But that is not the case. For example, if a compiler provides real-time extensions to C, NASA would use it without care for portability. The important point being the features are too good to sacrifice for a portability that is never used (I mean, who would compile the kernel with MS Visual Studio for example?)

链接地址: http://www.djcxy.com/p/73554.html

上一篇: 时间结构大小检查,如果奇数出错

下一篇: 标准C(gcc特定功能)?