Re: [PATCH 2.6.18-rc4-mm2] Generic boolean (was: Re: Generic booleans in -mm)
- From: Jan Engelhardt <jengelh@xxxxxxxxxxxxxxx>
- Date: Wed, 23 Aug 2006 14:06:10 +0200 (MEST)
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 '?'
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
bool, then the compiler will (hopefully) ensure that b will only get
values valid for bools.
$ cat x.c
#include <stdbool.h>
#include <stdio.h>
int main(int argc, const char **argv) {
_Bool b = argc;
printf("%d\n", (int)b);
return 0;
}
$ ./a.out
1
Jan Engelhardt
--
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
- Follow-Ups:
- Re: [PATCH 2.6.18-rc4-mm2] Generic boolean
- From: Richard Knutsson
- Re: [PATCH 2.6.18-rc4-mm2] Generic boolean
- References:
- [PATCH] Sgpio support in sata_nv
- From: Prajakta Gudadhe
- Re: [PATCH] Sgpio support in sata_nv
- From: Andrew Morton
- Generic booleans in -mm (was: Re: [PATCH] Sgpio support in sata_nv)
- From: Richard Knutsson
- Re: Generic booleans in -mm (was: Re: [PATCH] Sgpio support in sata_nv)
- From: Andrew Morton
- [PATCH 2.6.18-rc4-mm2] Generic boolean (was: Re: Generic booleans in -mm)
- From: Richard Knutsson
- [PATCH] Sgpio support in sata_nv
- Prev by Date: Re: [patch 1/5] fail-injection library
- Next by Date: Re: [RFC][PATCH] ps command race fix take2 [1/4] list token
- Previous by thread: [PATCH 2.6.18-rc4-mm2] Generic boolean (was: Re: Generic booleans in -mm)
- Next by thread: Re: [PATCH 2.6.18-rc4-mm2] Generic boolean
- Index(es):
Relevant Pages
|