Date: Wed, 30 Nov 2011 16:13:53 +1100 (EST) From: Bruce Evans <brde@optusnet.com.au> To: mdf@freebsd.org Cc: Zack Kirsch <zack@freebsd.org>, FreeBSD Arch <freebsd-arch@freebsd.org> Subject: Re: Use of bool / stdbool.h in kernel Message-ID: <20111130154604.B949@besplex.bde.org> In-Reply-To: <CAMBSHm_Be0hCimgg0KpCFs24MHOW=LBczJbFZ3F1cOaCgrS8LA@mail.gmail.com> References: <CAMBSHm_Be0hCimgg0KpCFs24MHOW=LBczJbFZ3F1cOaCgrS8LA@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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 <sys/stdbool.h>? 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 <sys/types.h>, 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 <stdbool.h> since it is older than C99, and it didn't use its own <mumble-bool.h> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20111130154604.B949>