Re: [PATCH 2.6.18-rc4-mm2] Generic boolean

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux