From: "Måns Rullgård" <mans@mansr.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] Introduce a global bool type
Date: Mon, 21 Jan 2013 23:08:57 +0000 [thread overview]
Message-ID: <yw1xlibmdth2.fsf@unicorn.mansr.com> (raw)
In-Reply-To: <1358808690.31204.7@snotra> (Scott Wood's message of "Mon, 21 Jan 2013 16:51:30 -0600")
Scott Wood <scottwood@freescale.com> writes:
> On 01/21/2013 04:36:42 PM, M?ns Rullg?rd wrote:
>> Scott Wood <scottwood@freescale.com> writes:
>>
>> > On 01/19/2013 03:30:30 AM, Albert ARIBAUD wrote:
>> >> /* what I favor */
>> >> clk_is_enabled = ((reg_val >> 9) & 1) ? true: false;
>> >> ip_is_enabled = clk_is_enabled && pwd_is_enabled;
>> >> if (clk_is_enabled) { ...
>> >>
>> >> rather than assigning them 'zero/nonzero', or using bitwise ops on
>> >> booleans, or testing against boolean constants (although I concede
>> >> that the first line below wins over its counterpart above as far as
>> >> concision is concerned).
>> >
>> > Conciseness can be improved with "!!((reg_val >> 9) & 1)".
>>
>> x & 1 is already either zero or one. Any further operations are
>> nothing
>> but obfuscation.
>
> The point is to avoid depending on the actual integer values of the
> boolean type,
Boolean expressions are defined to have a value of zero or one, and the
_Bool type (may it burn in hell) must be able to represent those values.
> and make the code more robust against changes (e.g. someone later
> comes along and says "hmm, that 1 should be a 3 because we care about
> that other register bit as well" without noticing that it's being
> assigned to a boolean.
If you stayed away from the silly _Bool type that wouldn't be a problem,
as long as any uses of the value treat all non-zero values equally, i.e.
only use it in a boolean context and not compare against explicit values
or perform arithmetic or bitwise logic operations on it.
In other words, boolifying on use rather than on assignment is generally
safer and usually at least as efficient.
--
M?ns Rullg?rd
mans at mansr.com
next prev parent reply other threads:[~2013-01-21 23:08 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-07 22:10 [U-Boot] [PATCH] Introduce a global bool type York Sun
2013-01-07 22:29 ` Scott Wood
2013-01-07 22:32 ` [U-Boot] [u-boot-release] " Timur Tabi
2013-01-07 22:39 ` [U-Boot] " Wolfgang Denk
2013-01-07 22:50 ` Scott Wood
2013-01-07 22:54 ` Måns Rullgård
2013-01-08 6:25 ` Wolfgang Denk
2013-01-08 16:51 ` Tabi Timur-B04825
2013-01-08 17:49 ` Wolfgang Denk
2013-01-08 17:53 ` Timur Tabi
2013-01-08 19:07 ` Wolfgang Denk
2013-01-08 19:09 ` Timur Tabi
2013-01-08 19:56 ` York Sun
2013-01-08 21:39 ` Wolfgang Denk
2013-01-08 21:43 ` York Sun
2013-01-08 21:46 ` Scott Wood
2013-01-19 9:30 ` Albert ARIBAUD
2013-01-21 18:05 ` Scott Wood
2013-01-21 22:36 ` Måns Rullgård
2013-01-21 22:51 ` Scott Wood
2013-01-21 23:08 ` Måns Rullgård [this message]
2013-01-22 7:41 ` Albert ARIBAUD
2013-01-22 12:59 ` Måns Rullgård
2013-01-08 18:34 ` Bernhard Walle
2013-01-08 19:08 ` Wolfgang Denk
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=yw1xlibmdth2.fsf@unicorn.mansr.com \
--to=mans@mansr.com \
--cc=u-boot@lists.denx.de \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox