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: ibm.com/developerworks/linux/library/l-g....
Wow, thanks for the great article. – SHH Nov 15 at 22:08.
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.
2 I don't know what gcc-extension features allow you to precisely control over a lot more stuff like memory layouts or maximizes efficiencies. Isn't that the job of assemly language specific to architecture? I mean if kernel developers wanted maximum efficiencies, why didn't they use assembly languages instead?
It looks like any gcc extensions used in kernel could have been replaced by Standard C (correct me if I am wrong). – SHH Nov 15 at 21:55 Writing assembly is much more time-consuming and difficult than writing C. Even in the kernel, it's limited to the areas where either a) it's simply not possible to express in C, or b) for very specific, performance critical pieces of code that the C compiler doesn't get "perfect".
Some of the extension used could probably be replaced by standard C, but what would be the point? If it's easier to write with exts, why bother? Also remember that the C standard evolves.
Some extensions get implemented by many compilers over time because they are useful. Then, eventually, they can become standard – Mat Nov 15 at 22:01 2 Lastly, and this is very important: the Linux kernel doesn't care about portability at all in the way ordinary applications do. They write the environment they run in and provide to userspace.
The portability the kernel cares about is entirely different from the portability of "ordinary" applications. – Mat Nov 15 at 22:03 @Mat: the Linux kernel sure cares about portability, that's why it uses a compiler that has been ported and generates code for a zillion architectures. – ninjalj Nov 15 at 23:14.
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?).
Not every hardware supported by gcc is provided with good features from gcc. – osgx Nov 15 at 21:50 What do you mean? The features I had in mind were of the type "statement-expression" and typeof as the OP had asked.
– Shahbaz Nov 15 at 23:22 I mean that gcc don't give good performance to every supported platform. – osgx Nov 16 at 0:27.
Once the kernel is compiled, it doesn't leave "traces" of its compilation environment around to taint the running kernel experience. I'd say it's just a matter of expedience. The kernel also contains bits of assembly, and assembly isn't exactly portable either.
Perhaps if the "mission" of the kernel was to write a kernel which could be compiled on multiple C compilers, the complaint would fall on more attentive ears.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.