* [KJ] what's the deal with using real "boolean" variables?
@ 2007-01-10 8:44 Robert P. J. Day
2007-01-10 9:23 ` Robert P. J. Day
` (9 more replies)
0 siblings, 10 replies; 11+ messages in thread
From: Robert P. J. Day @ 2007-01-10 8:44 UTC (permalink / raw)
To: kernel-janitors
is there a consensus on how to use actual C99 boolean variables in
the kernel source? C99 defines the unsigned integer type "_Bool" and,
from that point on, it's all downhill:
$ grep -ri "typedef.*bool" .
./drivers/scsi/BusLogic.h:typedef bool boolean;
./drivers/scsi/pci2000.h:typedef BOOL *PBOOL;
./drivers/telephony/ixj.h:typedef __u8 BOOL;
./drivers/block/DAC960.h:typedef bool boolean;
./drivers/video/riva/riva_hw.h:typedef int Bool;
./drivers/video/sis/vgatypes.h:typedef unsigned int BOOLEAN;
./arch/parisc/math-emu/float.h:typedef int boolean;
./include/acpi/actypes.h:typedef unsigned char BOOLEAN;
./include/linux/types.h:typedef _Bool bool;
./include/linux/efi.h:typedef u8 efi_bool_t;
... snip ...
./fs/xfs/xfs_types.h:typedef enum { B_FALSE,B_TRUE } boolean_t;
it seems like everyone has their own idea of what constitutes a
"boolean" variable. is there a "coding style" suggestion for this?
rday
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [KJ] what's the deal with using real "boolean" variables?
2007-01-10 8:44 [KJ] what's the deal with using real "boolean" variables? Robert P. J. Day
@ 2007-01-10 9:23 ` Robert P. J. Day
2007-01-10 9:24 ` Richard Knutsson
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Robert P. J. Day @ 2007-01-10 9:23 UTC (permalink / raw)
To: kernel-janitors
On Wed, 10 Jan 2007, Richard Knutsson wrote:
> Robert P. J. Day wrote:
> > is there a consensus on how to use actual C99 boolean variables in
> > the kernel source? C99 defines the unsigned integer type "_Bool" and,
> > from that point on, it's all downhill:
> >
> <snip>
> > ./include/linux/types.h:typedef _Bool bool;
> >
> This is the one that was added to replace the rest.
so the approved way to define boolean variables is with "bool," then?
ok, that makes sense. i was asking since that would be the obvious
return type of something like "is_power_of_2()", of course.
> There is also 'true' and 'false' defined (enum'ed) in include/linux/stddef.h.
>
> A few file-systems, including ntfs, has been converted to this one.
ah, yes, i see that now. it might be worth submitting a short patch
to update "CodingStyle" to mention all of this, if this is in fact the
consensus.
rday
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [KJ] what's the deal with using real "boolean" variables?
2007-01-10 8:44 [KJ] what's the deal with using real "boolean" variables? Robert P. J. Day
2007-01-10 9:23 ` Robert P. J. Day
@ 2007-01-10 9:24 ` Richard Knutsson
2007-01-10 9:48 ` Richard Knutsson
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Richard Knutsson @ 2007-01-10 9:24 UTC (permalink / raw)
To: kernel-janitors
Robert P. J. Day wrote:
> is there a consensus on how to use actual C99 boolean variables in
> the kernel source? C99 defines the unsigned integer type "_Bool" and,
> from that point on, it's all downhill:
>
<snip>
> ./include/linux/types.h:typedef _Bool bool;
>
This is the one that was added to replace the rest. I have not done too
much work on this for a while but should take it up soon again (but of
course, any help is appreciated).
There is also 'true' and 'false' defined (enum'ed) in
include/linux/stddef.h.
A few file-systems, including ntfs, has been converted to this one.
/Richard Knutsson
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [KJ] what's the deal with using real "boolean" variables?
2007-01-10 8:44 [KJ] what's the deal with using real "boolean" variables? Robert P. J. Day
2007-01-10 9:23 ` Robert P. J. Day
2007-01-10 9:24 ` Richard Knutsson
@ 2007-01-10 9:48 ` Richard Knutsson
2007-01-10 9:53 ` Alexey Dobriyan
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Richard Knutsson @ 2007-01-10 9:48 UTC (permalink / raw)
To: kernel-janitors
Robert P. J. Day wrote:
> On Wed, 10 Jan 2007, Richard Knutsson wrote:
>
>
>> Robert P. J. Day wrote:
>>
>>> is there a consensus on how to use actual C99 boolean variables in
>>> the kernel source? C99 defines the unsigned integer type "_Bool" and,
>>> from that point on, it's all downhill:
>>>
>>>
>> <snip>
>>
>>> ./include/linux/types.h:typedef _Bool bool;
>>>
>>>
>> This is the one that was added to replace the rest.
>>
>
> so the approved way to define boolean variables is with "bool," then?
> ok, that makes sense. i was asking since that would be the obvious
> return type of something like "is_power_of_2()", of course.
>
Sounds good
>
>> There is also 'true' and 'false' defined (enum'ed) in include/linux/stddef.h.
>>
>> A few file-systems, including ntfs, has been converted to this one.
>>
>
> ah, yes, i see that now. it might be worth submitting a short patch
> to update "CodingStyle" to mention all of this, if this is in fact the
> consensus.
>
Linus and Andrew added some functions whom used bool :)
I started on such a patch for "CodingStyle" but never got it to a
"ready-to-submit"-state.
/Richard Knutsson
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [KJ] what's the deal with using real "boolean" variables?
2007-01-10 8:44 [KJ] what's the deal with using real "boolean" variables? Robert P. J. Day
` (2 preceding siblings ...)
2007-01-10 9:48 ` Richard Knutsson
@ 2007-01-10 9:53 ` Alexey Dobriyan
2007-01-10 10:17 ` Richard Knutsson
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Alexey Dobriyan @ 2007-01-10 9:53 UTC (permalink / raw)
To: kernel-janitors
On 1/10/07, Robert P. J. Day <rpjday@mindspring.com> wrote:
> On Wed, 10 Jan 2007, Richard Knutsson wrote:
>
> > Robert P. J. Day wrote:
> > > is there a consensus on how to use actual C99 boolean variables in
> > > the kernel source? C99 defines the unsigned integer type "_Bool" and,
> > > from that point on, it's all downhill:
> > >
> > <snip>
> > > ./include/linux/types.h:typedef _Bool bool;
> > >
> > This is the one that was added to replace the rest.
>
> so the approved way to define boolean variables is with "bool," then?
> ok, that makes sense. i was asking since that would be the obvious
> return type of something like "is_power_of_2()", of course.
>
> > There is also 'true' and 'false' defined (enum'ed) in
> include/linux/stddef.h.
> >
> > A few file-systems, including ntfs, has been converted to this one.
>
> ah, yes, i see that now. it might be worth submitting a short patch
> to update "CodingStyle" to mention all of this, if this is in fact the
> consensus.
Before you'll decide whether consesus was reached, read thread
when TRUE and FALSE consolidation patch was first introduced.
Bonus points for getting a warning on this code:
void f(void)
{
bool foo = 42;
}
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [KJ] what's the deal with using real "boolean" variables?
2007-01-10 8:44 [KJ] what's the deal with using real "boolean" variables? Robert P. J. Day
` (3 preceding siblings ...)
2007-01-10 9:53 ` Alexey Dobriyan
@ 2007-01-10 10:17 ` Richard Knutsson
2007-01-10 10:31 ` Bernd Petrovitsch
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Richard Knutsson @ 2007-01-10 10:17 UTC (permalink / raw)
To: kernel-janitors
Alexey Dobriyan wrote:
> On 1/10/07, Robert P. J. Day <rpjday@mindspring.com> wrote:
>> On Wed, 10 Jan 2007, Richard Knutsson wrote:
>>
>> > Robert P. J. Day wrote:
>> > > is there a consensus on how to use actual C99 boolean variables in
>> > > the kernel source? C99 defines the unsigned integer type "_Bool"
>> and,
>> > > from that point on, it's all downhill:
>> > >
>> > <snip>
>> > > ./include/linux/types.h:typedef _Bool bool;
>> > >
>> > This is the one that was added to replace the rest.
>>
>> so the approved way to define boolean variables is with "bool," then?
>> ok, that makes sense. i was asking since that would be the obvious
>> return type of something like "is_power_of_2()", of course.
>>
>> > There is also 'true' and 'false' defined (enum'ed) in
>> include/linux/stddef.h.
>> >
>> > A few file-systems, including ntfs, has been converted to this one.
>>
>> ah, yes, i see that now. it might be worth submitting a short patch
>> to update "CodingStyle" to mention all of this, if this is in fact the
>> consensus.
>
> Before you'll decide whether consesus was reached, read thread
> when TRUE and FALSE consolidation patch was first introduced.
You mean the one started by akpm on March 16'th? There were much about
people who wanted FALSE/TRUE converted to 0/1. But since there is those
who wants booleans then a generic one is preferable, don't you think?
>
> Bonus points for getting a warning on this code:
>
> void f(void)
> {
> bool foo = 42;
> }
Hint: false is 0, true is !false (so that statement is actually correct.
But if you check "foo", you will find the value 1 :) )
But we have potential bugs because of some "self-made" booleans. For
example:
typedef boolean_t int;
#define FALSE 0
#define TRUE 1
...
boolean_t foo = 42;
if (foo =TRUE) {
...
/Richard Knutsson
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [KJ] what's the deal with using real "boolean" variables?
2007-01-10 8:44 [KJ] what's the deal with using real "boolean" variables? Robert P. J. Day
` (4 preceding siblings ...)
2007-01-10 10:17 ` Richard Knutsson
@ 2007-01-10 10:31 ` Bernd Petrovitsch
2007-01-10 10:57 ` walter harms
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Bernd Petrovitsch @ 2007-01-10 10:31 UTC (permalink / raw)
To: kernel-janitors
On Wed, 2007-01-10 at 11:17 +0100, Richard Knutsson wrote:
[...]
> if (foo =TRUE) {
This is IMHO ugly for any definition and implementation of boolean in C.
Write it as
if (foo) {
Otherwise why don't we write
if ((foo = TRUE) = TRUE) {
?
Bernd
--
Firmix Software GmbH http://www.firmix.at/
mobil: +43 664 4416156 fax: +43 1 7890849-55
Embedded Linux Development and Services
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [KJ] what's the deal with using real "boolean" variables?
2007-01-10 8:44 [KJ] what's the deal with using real "boolean" variables? Robert P. J. Day
` (5 preceding siblings ...)
2007-01-10 10:31 ` Bernd Petrovitsch
@ 2007-01-10 10:57 ` walter harms
2007-01-10 11:10 ` Richard Knutsson
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: walter harms @ 2007-01-10 10:57 UTC (permalink / raw)
To: kernel-janitors
hi,
i took a dive into the 'c reference manual' and found that the header stdbool.h
defines (#define) bool/true/false. It is permited to undefine and redefine these
defines. It defines also the macro "__bool_true_false_are_defined".
The best ways seems to emulate this way and provide a kernelbased stdbool.h if
"__bool_true_false_are_defined" does not exist.
my 2 cents,
walter
Richard Knutsson wrote:
> Alexey Dobriyan wrote:
>> On 1/10/07, Robert P. J. Day <rpjday@mindspring.com> wrote:
>>> On Wed, 10 Jan 2007, Richard Knutsson wrote:
>>>
>>>> Robert P. J. Day wrote:
>>>>> is there a consensus on how to use actual C99 boolean variables in
>>>>> the kernel source? C99 defines the unsigned integer type "_Bool"
>>> and,
>>>>> from that point on, it's all downhill:
>>>>>
>>>> <snip>
>>>>> ./include/linux/types.h:typedef _Bool bool;
>>>>>
>>>> This is the one that was added to replace the rest.
>>> so the approved way to define boolean variables is with "bool," then?
>>> ok, that makes sense. i was asking since that would be the obvious
>>> return type of something like "is_power_of_2()", of course.
>>>
>>>> There is also 'true' and 'false' defined (enum'ed) in
>>> include/linux/stddef.h.
>>>> A few file-systems, including ntfs, has been converted to this one.
>>> ah, yes, i see that now. it might be worth submitting a short patch
>>> to update "CodingStyle" to mention all of this, if this is in fact the
>>> consensus.
>> Before you'll decide whether consesus was reached, read thread
>> when TRUE and FALSE consolidation patch was first introduced.
> You mean the one started by akpm on March 16'th? There were much about
> people who wanted FALSE/TRUE converted to 0/1. But since there is those
> who wants booleans then a generic one is preferable, don't you think?
>> Bonus points for getting a warning on this code:
>>
>> void f(void)
>> {
>> bool foo = 42;
>> }
> Hint: false is 0, true is !false (so that statement is actually correct.
> But if you check "foo", you will find the value 1 :) )
> But we have potential bugs because of some "self-made" booleans. For
> example:
>
> typedef boolean_t int;
>
> #define FALSE 0
>
> #define TRUE 1
>
> ...
>
> boolean_t foo = 42;
>
> if (foo =TRUE) {
>
> ...
>
>
> /Richard Knutsson
>
> _______________________________________________
> Kernel-janitors mailing list
> Kernel-janitors@lists.osdl.org
> https://lists.osdl.org/mailman/listinfo/kernel-janitors
>
>
>
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [KJ] what's the deal with using real "boolean" variables?
2007-01-10 8:44 [KJ] what's the deal with using real "boolean" variables? Robert P. J. Day
` (6 preceding siblings ...)
2007-01-10 10:57 ` walter harms
@ 2007-01-10 11:10 ` Richard Knutsson
2007-01-10 11:37 ` Richard Knutsson
2007-01-10 13:34 ` Robert P. J. Day
9 siblings, 0 replies; 11+ messages in thread
From: Richard Knutsson @ 2007-01-10 11:10 UTC (permalink / raw)
To: kernel-janitors
Bernd Petrovitsch wrote:
> On Wed, 2007-01-10 at 11:17 +0100, Richard Knutsson wrote:
> [...]
>
>> if (foo =TRUE) {
>>
>
> This is IMHO ugly for any definition and implementation of boolean in C.
> Write it as
> if (foo) {
> Otherwise why don't we write
> if ((foo = TRUE) = TRUE) {
> ?
>
> Bernd
>
It sure is! But a quick check:
linux-2.6]$ grep -Er "\=\= *(TRUE|true)" * | wc -l
70
linux-2.6]$ grep -Er "\=\= *(FALSE|false)" * | wc -l
118
suggest it is used (saw a few false-positivs).
This is something that should be mentioned in "CodingStyle", but have
not got there yet. Care to make a draft/patch?
/Richard Knutsson
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [KJ] what's the deal with using real "boolean" variables?
2007-01-10 8:44 [KJ] what's the deal with using real "boolean" variables? Robert P. J. Day
` (7 preceding siblings ...)
2007-01-10 11:10 ` Richard Knutsson
@ 2007-01-10 11:37 ` Richard Knutsson
2007-01-10 13:34 ` Robert P. J. Day
9 siblings, 0 replies; 11+ messages in thread
From: Richard Knutsson @ 2007-01-10 11:37 UTC (permalink / raw)
To: kernel-janitors
walter harms wrote:
> hi,
> i took a dive into the 'c reference manual' and found that the header stdbool.h
> defines (#define) bool/true/false. It is permited to undefine and redefine these
> defines. It defines also the macro "__bool_true_false_are_defined".
> The best ways seems to emulate this way and provide a kernelbased stdbool.h if
> "__bool_true_false_are_defined" does not exist.
>
Why "__bool_true_false_are_defined" when we _know_ it is defined? Since
2.6.15 (I believe), only gcc >= 3.2 is supported, and from version 3,
gcc supports _Boole.
I first thought to implement it as stdbool.h, but the consensus seems to
be: types in linux/types.h and false/true found a home in linux/stddef.h.
/Richard Knutsson
PS
Please don't top-post. :)
DS
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [KJ] what's the deal with using real "boolean" variables?
2007-01-10 8:44 [KJ] what's the deal with using real "boolean" variables? Robert P. J. Day
` (8 preceding siblings ...)
2007-01-10 11:37 ` Richard Knutsson
@ 2007-01-10 13:34 ` Robert P. J. Day
9 siblings, 0 replies; 11+ messages in thread
From: Robert P. J. Day @ 2007-01-10 13:34 UTC (permalink / raw)
To: kernel-janitors
On Wed, 10 Jan 2007, Richard Knutsson wrote:
> Bernd Petrovitsch wrote:
> > On Wed, 2007-01-10 at 11:17 +0100, Richard Knutsson wrote:
> > [...]
> >
> >> if (foo =TRUE) {
> >>
> >
> > This is IMHO ugly for any definition and implementation of boolean in C.
> > Write it as
> > if (foo) {
> > Otherwise why don't we write
> > if ((foo = TRUE) = TRUE) {
> > ?
> >
> > Bernd
> >
> It sure is! But a quick check:
> linux-2.6]$ grep -Er "\=\= *(TRUE|true)" * | wc -l
> 70
> linux-2.6]$ grep -Er "\=\= *(FALSE|false)" * | wc -l
> 118
> suggest it is used (saw a few false-positivs).
>
> This is something that should be mentioned in "CodingStyle", but
> have not got there yet. Care to make a draft/patch?
oh, god ... what have i started *this* time? :-P
rday
_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2007-01-10 13:34 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-01-10 8:44 [KJ] what's the deal with using real "boolean" variables? Robert P. J. Day
2007-01-10 9:23 ` Robert P. J. Day
2007-01-10 9:24 ` Richard Knutsson
2007-01-10 9:48 ` Richard Knutsson
2007-01-10 9:53 ` Alexey Dobriyan
2007-01-10 10:17 ` Richard Knutsson
2007-01-10 10:31 ` Bernd Petrovitsch
2007-01-10 10:57 ` walter harms
2007-01-10 11:10 ` Richard Knutsson
2007-01-10 11:37 ` Richard Knutsson
2007-01-10 13:34 ` Robert P. J. Day
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.