From: walter harms <wharms@bfs.de>
To: kernel-janitors@vger.kernel.org
Subject: Re: [KJ] what's the deal with using real "boolean" variables?
Date: Wed, 10 Jan 2007 10:57:38 +0000 [thread overview]
Message-ID: <45A4C6A2.9070303@bfs.de> (raw)
In-Reply-To: <Pine.LNX.4.64.0701100337460.11933@localhost.localdomain>
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
next prev parent reply other threads:[~2007-01-10 10:57 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2007-01-10 11:10 ` Richard Knutsson
2007-01-10 11:37 ` Richard Knutsson
2007-01-10 13:34 ` Robert P. J. Day
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=45A4C6A2.9070303@bfs.de \
--to=wharms@bfs.de \
--cc=kernel-janitors@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.