weeding out c++ keywords from sys/sys

Christoph Mallon christoph.mallon at gmx.de
Sun Feb 15 07:33:22 PST 2009


Gary Jennejohn schrieb:
> On Sun, 15 Feb 2009 13:00:15 +0000
> Bruce Simpson <bms at incunabulum.net> wrote:
> 
>> Please don't listen to the nay-sayers, and keep up the good work:-
>>     
>> http://web.archive.org/web/20071222161357/http://netlab.ru.is/exception/LinuxCXX.shtml
>>
> 
> It isn't exactly confidence building that all the links on this page
> are invalid.
> 
> This is all from 2005 and AFAICT has languished since then.  I'm not aware of
> any movement within the Linux community to bring C++ support into the kernel.
> 
>> Nay-sayers: All I ask is that you don't complain when someone who knows 
>> how to use the tool, and has the support, gets more working code written :^)
>>
> 
> I haven't been paying much attention to this thread, but I can't recall
> having read any persuasive arguments for using C++ in the kernel.

More robust error handling and less tedious resouce management directly 
come to mind:
Just look at normal C functions which allocate resources and have 
multiple points which can fail. They are the usual mess of if()s, goto 
error and lots of cleanup code. Further all this code looks pretty much 
the same in several modules. In C++ you write the resource handling code 
once (constructors/destructors) and then you cannot forget to clean up, 
because thanks to scoping and defined life ranges it happens automatically.
Further return codes are ignored by default, which happens all too 
easily. Exceptions cause the normal code path to be aborted instead of 
limping further after failure probably with uninitialised data. Also 
exceptions which do not occure are faster than normal error code 
checking. Assume a chain of a dozen functions is called to handle 
something and the innermost can fail. Then every one of these functions 
has to have a return code to signal an error and every one of these 
functions has to check the one of its callee(s). This is not only 
tedious (see above), but it means a check on every level. With 
exceptions only the inner function throws an exception on failure and 
all the other functions do not have to check for failure - so there is 
no if() on the normal code path for all these calls. Exceptions cost 
nothing when they do not occure; a try {} block does not cause any code 
on the normal program path to be executed.
These are two arguments for C++ which, I hope, are convincing to you. 
C++ adds more interesting aspects, but these two immediately come to 
mind when thinking about the usual stuff an OS does.

> I personally get cold chills up and down my spine just thinking about it.

Why? Do you have any arguments?

> Maybe I've been doing kernel development for too long.

Look a bit around. Modern languages try to make it easier to create 
robust code. I think C++ got some things right.

Regards
	Christoph


More information about the freebsd-current mailing list