Re: RFC: booleans and the kernel

From: Werner Almesberger (wa@almesberger.net)
Date: Fri Jan 25 2002 - 10:07:50 EST


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 <stdbool.h>
#include <stdio.h>

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/



This archive was generated by hypermail 2b29 : Thu Jan 31 2002 - 21:00:32 EST