lkml.org 
[lkml]   [2006]   [Aug]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: [PATCH 2.6.18-rc4-mm2] Generic boolean
    Jan Engelhardt wrote:

    >Hi,
    >
    >
    >
    >
    >>There has been concern about adding other values then 0 and 1. There has been
    >>ideas to do something like:
    >>bool b = i & 1 : 0;
    >>
    >>
    >
    >I think you miseed a '?'
    >
    >
    Yes, thanks...

    >bool b = (i & 1) ? : 0;
    >
    >
    ...but I meant: bool b = i ? 1 : 0;

    >
    >
    >>/*or*/
    >>bool b = !!i;
    >>
    >>but all that is needed is just a casting:
    >>
    >>bool b = (bool) i;
    >>
    >>
    >
    >No casting needed (in fact, casting is more evil than !!). If bool is a
    >
    >
    Please inform me why casting is evil (other then risking losing data, by
    cutting the value). But also, _Bool-casting is after all a bit special
    since it does not seem (at least by me) to be able to get a wrong value
    (giving it a value other then 0 but reciving 0).

    >bool, then the compiler will (hopefully) ensure that b will only get
    >values valid for bools.
    >
    >
    No, not really. Because _Bool is a byte and not a bit, you can put in a
    value other then 0 or 1 if you cast the pointer (if you insert 256 it
    becomes 0). But after all, there should not be any:
    if (b == true)
    in the code anyway, so it should be ok.

    >Jan Engelhardt
    >
    >
    /Richard Knutsson
    -
    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/

    \
     
     \ /
      Last update: 2006-08-24 06:03    [W:0.021 / U:0.524 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site