C++ in the kernel

Poul-Henning Kamp phk at phk.freebsd.dk
Mon Oct 29 14:22:26 PDT 2007


In message <fg4bij$m42$1 at ger.gmane.org>, Ivan Voras writes:
>Poul-Henning Kamp wrote:
>> In message <20071028074310.233895B3E at mail.bitblocks.com>, Bakul Shah writes:
>> 
>>> It will be the proverbial camel's nose in the tent.  A subset
>>> of C++ is attractive for kernel work but it will be hard to
>>> hold the line at that.
>> 
>> That's one of my main arguments why we should "own the language" we
>> use.
>
>A bit of the "NIH syndrome" here? :)

Not really.  I've personally bugged Bjarne about making C++ usable
for systems programming ever since 1987 or so, but to no avail.

If you look at kernel code, you will find that the kind of things
we do there, are slightly but importantly different from what C++
and other more modern languages are built to handle.

For instance, the entire "dual-address space" dictomy og system
calls/copy{in,out} and the very concept of interrupts are very
tricky to sensibly express in anything but C.

So what I've been tinkering with, is not a new language, but a
C dialect enhanced to make kernel programming simpler.

>> The other main argument is that we can then teach the language to
>> do the things we need it to do.
>
>The less people know the language, the less it will be used. A "one-off"
>language (like "K") applicable only for FreeBSD is not exactly doomed to
>popularity.

I'm not trying to come up with a language to end all languages, I
leave that for greater minds than mine.  All I want is a compiler
and a language that makes it easy for me to write bugfree, efficient
and readable kernel code.

One thing that particularly bothers me, is that compilers offer
no assistance in debugging, because normal programming runs in the
UNIX virtual machine, attaching a debugger is the preferred way.

In the kernel we don't have that luxury, and there are a number
of ways the compiler could help us.

Imagine for instance an option to zap the heap with 0xdeadcode on
function return or an option to check all function pointers for
non-null-ness before jumping through them.

-- 
Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
phk at FreeBSD.ORG         | TCP/IP since RFC 956
FreeBSD committer       | BSD since 4.3-tahoe    
Never attribute to malice what can adequately be explained by incompetence.


More information about the freebsd-arch mailing list