From owner-freebsd-standards@FreeBSD.ORG Wed Dec 31 20:57:16 2003 Return-Path: Delivered-To: freebsd-standards@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 373DA16A4CE; Wed, 31 Dec 2003 20:57:16 -0800 (PST) Received: from mailman.zeta.org.au (mailman.zeta.org.au [203.26.10.16]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6426043D4C; Wed, 31 Dec 2003 20:57:13 -0800 (PST) (envelope-from bde@zeta.org.au) Received: from gamplex.bde.org (katana.zip.com.au [61.8.7.246]) by mailman.zeta.org.au (8.9.3p2/8.8.7) with ESMTP id PAA09351; Thu, 1 Jan 2004 15:52:09 +1100 Date: Thu, 1 Jan 2004 15:52:08 +1100 (EST) From: Bruce Evans X-X-Sender: bde@gamplex.bde.org To: Jason Evans In-Reply-To: <20040101004057.19C541C5@canonware.com> Message-ID: <20040101153143.N7624@gamplex.bde.org> References: <20040101004057.19C541C5@canonware.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: FreeBSD-gnats-submit@freebsd.org cc: freebsd-standards@freebsd.org Subject: Re: standards/60772: _Bool and bool should be unsigned X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Jan 2004 04:57:16 -0000 On Wed, 31 Dec 2003, Jason Evans wrote: > >Release: FreeBSD 4.9-RC i386 ^^^^^^^^^^^ > >Description: > _Bool and bool must be unsigned, so that structure bit fields work as > expected. > >How-To-Repeat: > #include > #include > > /* _Bool and bool must be unsigned. Otherwise, stucture bit fields do not work > * correctly, due to how sign extension works. */ > > struct foo { > bool white:1; /* Note :1 (bit field). */ > }; This works correctly with C99 compilers, e.g., in with the not-quite-C99 compiler gcc in -current and even with the non-C99 compiler "gcc -c89" in -current, since bool is an alias for _Bool and _Bool is a builtin type (neither signed nor unsigned) that can only represent the values 0 and 1. > > struct bar { > bool white:2; > }; This also doesn't really work in FreeBSD-4.9, since it can store more than the values of 0 and 1. Similarly for a non-bitfield. The fake definition in FreeBSD-4.9 permits storing values between INT_MIN and INT_MAX, and changing it to unsigned so that it is limited to values between 0 and UINT_MAX isn't much of an improvment. > >Fix: > Using bit fields with more than one bit works around the problem, but is > not a satisfactory workaround. This bug can cause obscure problems, since > something like: > > if (foo.white == true) ...; > > breaks. I think the correct fix is to remove in RELENG_4, since it is impossible to implement it correctly. It's more dangerous than it used to be since programs that use it are more likely to expect it to give C99 semantics. Was there a defacto standard for it before C99? It doesn't seem to have been very common -- it isn't in glibc-2.2.5 (which is 2 years old, but not as old as in FreeBSD). Bruce