From: Siarhei Siamashka <siarhei.siamashka@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 2/2] musb: sunxi: Implement dfu_usb_get_reset()
Date: Sun, 25 Oct 2015 22:48:42 +0200 [thread overview]
Message-ID: <20151025224842.76d500a3@i7> (raw)
In-Reply-To: <1445801044.28851.14.camel@hellion.org.uk>
On Sun, 25 Oct 2015 19:24:04 +0000
Ian Campbell <ijc+uboot@hellion.org.uk> wrote:
> On Sun, 2015-10-25 at 16:46 +0200, Siarhei Siamashka wrote:
> > replace "#include <stdbool.h>" with "typedef int bool;" and try it
> > again.
>
> So don't do that then.
Yes, I'm not going to do this. It was just an artificial example,
demonstrating how things work. I'm only a little bit worried about
a potential rogue typedef unexpectedly coming from one of the
include files one day.
> In u-boot the "bool" type comes from stdbool.h and it is therefore
> completely reasonable to assume that bool in u-boot has the properties
> which this implies.
Right, except that there are still a few bool related typedefs
in the code:
https://github.com/u-boot/u-boot/blob/v2015.10/lib/lzma/Types.h#L83
https://github.com/u-boot/u-boot/blob/v2015.10/lib/bzip2/bzlib_private.h#L85
Yes, they come from third-party libraries and don't really redefine
bool or _Bool. But the C language did not always have a native bool
data type. And historically it had been a common practice to typedef
bool to some integer type. One should not be very much surprised upon
encountering such code in the wild even now.
Regarding the code efficiency. The following example:
#include <stdbool.h>
bool foo(int x)
{
return x & 4;
}
bool bar(int x)
{
return !!(x & 4);
}
Compiles into the following code on ARM:
00000000 <foo>:
0: e7e00150 ubfx r0, r0, #2, #1
4: e12fff1e bx lr
00000008 <bar>:
8: e7e00150 ubfx r0, r0, #2, #1
c: e12fff1e bx lr
Basically, there is exactly no difference. And removing "!!" only
has a cosmetic value for the code that uses the bool definition
from <stdbool.h>.
As I already said, I'm perfectly fine with either of these variants :-)
The purists are welcome to start a crusade eliminating all of the uses
of the "!!" construct in the U-Boot code. Probably starting with the
other dfu_usb_get_reset() implementations for the sake of consistency:
https://github.com/u-boot/u-boot/blob/v2015.10/drivers/usb/gadget/s3c_udc_otg.c#L151
https://github.com/u-boot/u-boot/blob/v2015.10/drivers/usb/gadget/ci_udc.c#L1062
--
Best regards,
Siarhei Siamashka
next prev parent reply other threads:[~2015-10-25 20:48 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-25 4:44 [U-Boot] [PATCH 0/2] Enable DFU for RAM on Allwinner devices Siarhei Siamashka
2015-10-25 4:44 ` [U-Boot] [PATCH 1/2] sunxi: Enable DFU for RAM Siarhei Siamashka
2015-11-20 15:21 ` [U-Boot] [U-Boot,1/2] " Hans de Goede
2015-10-25 4:44 ` [U-Boot] [PATCH 2/2] musb: sunxi: Implement dfu_usb_get_reset() Siarhei Siamashka
2015-10-25 11:00 ` Marek Vasut
2015-10-25 11:46 ` Albert ARIBAUD
2015-10-25 12:40 ` Ian Campbell
2015-10-25 13:22 ` Albert ARIBAUD
2015-10-25 13:29 ` Marek Vasut
2015-10-25 14:46 ` Siarhei Siamashka
2015-10-25 16:08 ` Marek Vasut
2015-10-25 19:24 ` Ian Campbell
2015-10-25 20:48 ` Siarhei Siamashka [this message]
2015-10-25 19:22 ` Ian Campbell
2015-10-25 21:16 ` Albert ARIBAUD
2015-10-26 10:07 ` Ian Campbell
2015-10-26 11:32 ` Albert ARIBAUD
2015-10-25 14:55 ` Siarhei Siamashka
2015-10-25 16:09 ` Marek Vasut
2015-10-25 21:19 ` Albert ARIBAUD
2015-10-26 11:18 ` [U-Boot] [PATCH 0/2] Enable DFU for RAM on Allwinner devices Piotr Król
2015-10-27 4:31 ` Siarhei Siamashka
2015-10-27 23:27 ` Piotr Król
2015-10-28 4:49 ` Siarhei Siamashka
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=20151025224842.76d500a3@i7 \
--to=siarhei.siamashka@gmail.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