Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id ; Fri, 25 Jan 2002 10:08:37 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id ; Fri, 25 Jan 2002 10:08:27 -0500 Received: from lsb-catv-1-p021.vtxnet.ch ([212.147.5.21]:18445 "EHLO almesberger.net") by vger.kernel.org with ESMTP id ; Fri, 25 Jan 2002 10:08:12 -0500 Date: Fri, 25 Jan 2002 16:07:50 +0100 From: Werner Almesberger To: "H. Peter Anvin" Cc: linux-kernel@vger.kernel.org Subject: Re: RFC: booleans and the kernel Message-ID: <20020125160750.A18035@almesberger.net> In-Reply-To: <200201242141.g0OLfjL06681@home.ashavan.org.> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: ; from hpa@zytor.com on Thu, Jan 24, 2002 at 02:21:28PM -0800 Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org H. Peter Anvin wrote: > c) The ability to cast to bool and get an unambiguous true or false: > > b = (bool)a; > > This replaces the idiomatic but occationally confusing > > b = !!a; Careful, though. This example #include #include int main(void) { int foo; foo = (bool) 4; printf("%d\n",foo); return 0; } e.g. compiled with gcc "2.96" (RH 7.1, 2.96-85), yields 4. Not sure if this is a flaw of gcc or of the standard. If gcc's stdbool.h is a standard-compliant implementation of "bool", then K&Rv2 seems to endorse this behaviour: from A4.2, "Enumerations behave like integers". - Werner -- _________________________________________________________________________ / Werner Almesberger, Lausanne, CH wa@almesberger.net / /_http://icawww.epfl.ch/almesberger/_____________________________________/ - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/