From owner-freebsd-arch@FreeBSD.ORG Sun Dec 4 16:49:09 2011 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 217F0106564A; Sun, 4 Dec 2011 16:49:09 +0000 (UTC) (envelope-from mdf356@gmail.com) Received: from mail-pz0-f54.google.com (mail-pz0-f54.google.com [209.85.210.54]) by mx1.freebsd.org (Postfix) with ESMTP id DF9568FC08; Sun, 4 Dec 2011 16:49:08 +0000 (UTC) Received: by dakp5 with SMTP id p5so216616dak.13 for ; Sun, 04 Dec 2011 08:49:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=suMCRAN9R1H+1Q4FHASw4vitAsCqHEJEksr53wZexkQ=; b=nS3b8LZqHoy1kjfzZZCnwHIMRPlTSMfNB727rsjSC5qilAgq9Or20o0NBusszptAy6 czlWAClVy1QRLBVviCtNuPysjv4j6WsPUps4bwYcAzkN+GIAPRnja3SB4KfIZGCafJaI IQoHeWssoerB3DCMYPHQ7BoMT83tEdFN+ebf4= MIME-Version: 1.0 Received: by 10.68.31.200 with SMTP id c8mr15571921pbi.8.1323017348256; Sun, 04 Dec 2011 08:49:08 -0800 (PST) Sender: mdf356@gmail.com Received: by 10.68.56.97 with HTTP; Sun, 4 Dec 2011 08:49:08 -0800 (PST) In-Reply-To: <201111301032.04102.jhb@freebsd.org> References: <20111130154604.B949@besplex.bde.org> <201111301032.04102.jhb@freebsd.org> Date: Sun, 4 Dec 2011 08:49:08 -0800 X-Google-Sender-Auth: 1W6EExx4SoHz_5AXc8BlcPMmvc0 Message-ID: From: mdf@FreeBSD.org To: John Baldwin Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: Zack Kirsch , freebsd-arch@freebsd.org Subject: Re: Use of bool / stdbool.h in kernel X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 04 Dec 2011 16:49:09 -0000 On Wed, Nov 30, 2011 at 7:32 AM, John Baldwin wrote: > On Wednesday, November 30, 2011 12:13:53 am Bruce Evans wrote: >> On Tue, 29 Nov 2011 mdf@freebsd.org wrote: >> >> > At $WORK we have a hack in one of the *.mk files to allow including >> > stdbool.h in the kernel and we use it extensively. =A0This is not >> > allowed by style(9), as far as I can tell, because the file is in >> > include/stdbool.h and those files are not allowed to be included in >> > kernel sources. >> >> Including stdbool.h in the kernel is not a style bug, but unsupported. >> >> > What I want to check on is, would it be acceptable to move stdbool.h >> > from include/stdbool.h to sys/sys/stdbool.h (i.e. like errno.h) and >> > then include it in the kernel as ? =A0That is, is the >> >> Would be a larger style bug, especially if it were actually used. >> Even its spellings of TRUE and FALSE are strange. =A0Even in userland >> stdbool.h is considered so useful that it is never used in src/bin >> and is only used a few times on other src/*bin. =A0src/bin never uses >> TRUE of FALSE either. > > I suspect there is some bias here though due to the fact that there wasn'= t > a standard bool type when most of this code was written. :) =A0I don't th= ink > that means we have to forgo use of the new type now that it is in fact > standardized in C99. =A0I would be happy to have 'bool' available and the > lowercase 'true' and 'false' are fine with me. In further thinking, there's also a style issue of nested headers. FreeBSD expects most types defined in sys/types.h so that it can be included first and other files alphabetically. Using would require any header with a bool parameter, return code, or struct member to include . Alternatively, I could instead put the same guards as stdbool.h uses and define bool, true, and false in sys/types.h, but only for _KERNEL use (however, this also would create issues with any file that is built in both user-space and kernel, and unconditionally defining in sys/types.h could break existing buggy applications). *sigh*, part of the problem is the buggy way in which C99 added the bool type. I suppose code could always use the real reserved keyword _Bool in headers, ugly though it is, and bool in implementation files. I had a brief look, and for comparison Linux has the typedef in linux/include/types.h IIRC but does not guard the definition nor did it define true/false. Thanks, matthew