From owner-freebsd-current@FreeBSD.ORG Sun Feb 15 15:33:21 2009 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C12041065670 for ; Sun, 15 Feb 2009 15:33:21 +0000 (UTC) (envelope-from christoph.mallon@gmx.de) Received: from mail.gmx.net (mail.gmx.net [213.165.64.20]) by mx1.freebsd.org (Postfix) with SMTP id 37C808FC15 for ; Sun, 15 Feb 2009 15:33:20 +0000 (UTC) (envelope-from christoph.mallon@gmx.de) Received: (qmail invoked by alias); 15 Feb 2009 15:33:19 -0000 Received: from p54A3DABF.dip.t-dialin.net (EHLO tron.homeunix.org) [84.163.218.191] by mail.gmx.net (mp058) with SMTP; 15 Feb 2009 16:33:19 +0100 X-Authenticated: #1673122 X-Provags-ID: V01U2FsdGVkX19d9ZFu6mtdNdVfxRLWJUV1Yzmtdeg4oQ5uv9DGWk N4/KdOtlJ/3bDr Message-ID: <499835BE.3000705@gmx.de> Date: Sun, 15 Feb 2009 16:33:18 +0100 From: Christoph Mallon User-Agent: Thunderbird 2.0.0.19 (X11/20090103) MIME-Version: 1.0 To: gary.jennejohn@freenet.de References: <4995BB1B.7060201@icyb.net.ua> <20090213231513.GA20223@duncan.reilly.home> <4997F105.5020409@icyb.net.ua> <499811DF.6030905@incunabulum.net> <20090215151318.0d17bfb9@ernst.jennejohn.org> In-Reply-To: <20090215151318.0d17bfb9@ernst.jennejohn.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Y-GMX-Trusted: 0 X-FuHaFi: 0.54 Cc: Andrew Reilly , Bruce Simpson , Andriy Gapon , freebsd-current@freebsd.org Subject: Re: weeding out c++ keywords from sys/sys X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 15 Feb 2009 15:33:22 -0000 Gary Jennejohn schrieb: > On Sun, 15 Feb 2009 13:00:15 +0000 > Bruce Simpson 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