[lkml]   [2002]   [Jan]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
    SubjectRe: RFC: booleans and the kernel
    Followup to:  <>
    By author: Oliver Xymoron <>
    In newsgroup:
    > > It doesn't fix "if ( x = true)". If would
    > > just make it more legit to use "if (x)".
    > It's been legit and idiomatic since day 1, if not sooner.

    The main reasons for bool is:

    a) The ability to save space. No need to waste a 32- or 64-bit word
    to hold a single bit. If you're on an architecture that has flags
    or predicates you may be able to carry a boolean in such a value
    instead of in a full register.

    b) Compatibility with other languages, including but not limited to
    C++ (there is a standard under development for inter-language linking,
    incidentally.) C++, of course, needs bool for overloading reasons.

    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;

    d) Similarly, you can avoid doing booleanization multiple times:

    /* Highly artificial example */
    int foo(bool a)
    return a ? 55 : 47;

    ... could be implemented by the compiler as 47 + (a << 3), or
    depending on your ABI convention, perhaps a caller calling
    foo(x < 4) could be implemented as foo(x-4) without needing to
    convert it into an integer of exactly 1 and 0.

    Given the way C currently does it, you pretty much have do
    booleanize both in the caller and the callee to be on the safe


    <> at work, <> in private!
    "Unix gives you enough rope to shoot yourself in the foot." <>
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to
    More majordomo info at
    Please read the FAQ at

     \ /
      Last update: 2005-03-22 13:15    [W:0.024 / U:38.856 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site