From owner-freebsd-arch@FreeBSD.ORG Wed Nov 30 05:13:59 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 C3C3E106566B; Wed, 30 Nov 2011 05:13:59 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail04.syd.optusnet.com.au (mail04.syd.optusnet.com.au [211.29.132.185]) by mx1.freebsd.org (Postfix) with ESMTP id 615168FC0C; Wed, 30 Nov 2011 05:13:58 +0000 (UTC) Received: from c211-28-227-231.carlnfd1.nsw.optusnet.com.au (c211-28-227-231.carlnfd1.nsw.optusnet.com.au [211.28.227.231]) by mail04.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id pAU5Drfa005532 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 30 Nov 2011 16:13:54 +1100 Date: Wed, 30 Nov 2011 16:13:53 +1100 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: mdf@freebsd.org In-Reply-To: Message-ID: <20111130154604.B949@besplex.bde.org> References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: Zack Kirsch , FreeBSD Arch 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: Wed, 30 Nov 2011 05:13:59 -0000 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. This 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 ? That is, is the Would be a larger style bug, especially if it were actually used. Even its spellings of TRUE and FALSE are strange. Even 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. src/bin never uses TRUE of FALSE either. > objection / non-use because of where the file is located in the > repository, or is there some other reason? Note that the pre-C99 > boolean_t and TRUE/FALSE are spread over the kernel, mostly in sys/vm > where I assume they come from old AT&T sources. Thes came from mach vm. Pure BSD code never uses them. For example, in 4.4BSD-Lite2 /sys/kern, FALSE is used 3 times, all to call vm functions whose API uses it, while TRUE is used 3 times, once for a vm call and twice in shell scripts where it is an unquoted string. Pure BSD code also never uses booleans. It uses explicit comparisons with 0, which is equivalent to always spelling FALSE as 0 and both !FALSE and TRUE as either 1 or another literal more-magic number or "!= 0" (never !0 or !(expr) since those are booleans !!). In 1995, I made the mistake of moving the mach definitions of FALSE and TRUE and the declaration of boolean_t from a vm header to , because I wanted to use them more globally and I didn't know BSD style very well at the time. Especially that it never uses booleans. 4.4Lite2 could not have used C99's since it is older than C99, and it didn't use its own since it preferred explicit 0's and 1's. You may wish to change this style, but then all old BSD code would not conform to the new style. Bruce