Linux.com

Am I C-ing this right?

Link to this post 12 May 11

Thanks for your feedback.

However, to elaborate a bit more, my thoughts were that:
as [far as I could see] the Kernel writers continue to write it just in C, and they presumably do so because they regard it to be better than C++
and so shouldn't I just follow their lead and not bother with continuing to try to learn C++?

If it's not: [arguably] better than C++ (and your replies suggest to me that it is not), then whatever are their reasons for continuing/[prefering] to write it in C?

Link to this post 12 May 11

There are other reasons for writing kernel code in C instead of C++, than that people think it is "better" than C++. There are things that C++ does that won't play nice in the down-to-the-metal environment of the kernel, such as virtual functions, etc. It may be possible to write kernel modules in C++, but it would be so restricted that it would end up pretty much just C code.

Myself, when I design and write seriously complex enterprise applications, C++ is my language of choice. When I write kernel code, I use C.

Link to this post 12 May 11

Noluk wrote:

Thanks for your feedback.

However, to elaborate a bit more, my thoughts were that:
as [far as I could see] the Kernel writers continue to write it just in C, and they presumably do so because they regard it to be better than C++
and so shouldn't I just follow their lead and not bother with continuing to try to learn C++?

If it's not: [arguably] better than C++ (and your replies suggest to me that it is not), then whatever are their reasons for continuing/[prefering] to write it in C?

They write in C because it's *faster*. That doesn't mean it's better though: it's better for kernel programming as the speed is key to usefulness of the kernel.

From an application development point of view, C++ is better as it was designed for code reutilization and object oriented programming (usually more understandable by our brain).

As usual, it's a matter of balance :)

Regards

Link to this post 14 May 11

Marc Deop wrote:

They write in C because it's *faster*

What sort of [rough guide] figure would apply to that?
Would that still be true in the following event:

Rubberman wrote:


It may be possible to write kernel modules in C++, but it would be so restricted that it would end up pretty much just C code.

That is to say:
Does the C code always compile to faster, more efficient machine code than C++ ?

Link to this post 14 May 11

The speed not only depends on the language but most of the times C code will be faster than C++ .Note that we are talking here about *SMALL* figures, that is like 1ms faster in calling a function which is nothing from an application point of view but could be important in a kernel thing ;)

Link to this post 16 May 11

That helps; thank you for the insight.

Who we are ?

The Linux Foundation is a non-profit consortium dedicated to the growth of Linux.

More About the foundation...

Frequent Questions

Join / Linux Training / Board