[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <44ED25AE.9030003@student.ltu.se>
Date: Thu, 24 Aug 2006 06:06:06 +0200
From: Richard Knutsson <ricknu-0@...dent.ltu.se>
To: Jan Engelhardt <jengelh@...ux01.gwdg.de>
CC: Andrew Morton <akpm@...l.org>,
Prajakta Gudadhe <pgudadhe@...dia.com>, jeff@...zik.org,
linux-kernel@...r.kernel.org
Subject: Re: [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@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists