Why is linux kernel coded using non-standard C (gcc specific features)? [closed] Why is linux kernel coded using non-standard C (gcc specific features)? [closed] c c

Why is linux kernel coded using non-standard C (gcc specific features)? [closed]


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:

https://developer.ibm.com/tutorials/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?)