[U-Boot] [PATCH 2/2] musb: sunxi: Implement dfu_usb_get_reset()

Albert ARIBAUD albert.u.boot at aribaud.net
Mon Oct 26 12:32:02 CET 2015


Hello Ian,

On Mon, 26 Oct 2015 10:07:24 +0000, Ian Campbell
<ijc+uboot at hellion.org.uk> wrote:
> On Sun, 2015-10-25 at 22:16 +0100, Albert ARIBAUD wrote:
> > Hello Ian,
> > 
> > On Sun, 25 Oct 2015 19:22:00 +0000, Ian Campbell
> > <ijc+uboot at hellion.org.uk> wrote:
> > > On Sun, 2015-10-25 at 14:22 +0100, Albert ARIBAUD wrote:
> > > > On Sun, 25 Oct 2015 12:40:45 +0000, Ian Campbell
> > > > > Doesn't the bool return type already cause that to happen?
> > (from the
> > > > > PoV of the caller at least)
> > > > 
> > > > When all is said and done, a C bool is a C int,
> > > 
> > > Not if it is a _Bool (via stdbool.h or some other way).
> > > 
> > > A _Bool is always either 0 or 1, and scalar value which is
> > converted to
> > > a _Bool is converted to either 0 or 1.
> > >
> > > > So no, types, bool or otherwise, do not cause any implicit '!!'
> > to
> > > > happen.
> > > 
> > > I believe this is not correct when _Bool is used.
> > > 
> > > In u-boot a bool is indeed a _Bool (or at least I don't see any
> > other
> > > typedef's and I can see various includes on stdbool.h, I therefore
> > > didn't feel the need to check how bool is arrived at in this
> > particular
> > > file).
> > 
> > What you write is possibly correct for C++, but certainly not for C,
> > for which booleans are integers, with no compiler-enforced constraint
> > on their value domains.
> 
> I know next to nothing about C++ so I am certainly not confusing things
> with that.
> 
> The _Bool type in C99 is an integer which may take on exactly the
> values 0 or 1. Since the code which started this subthread was using
> "bool" from <stdbool.h> it is _Bool which is being discussed here.
> 
> The actual standard costs money (and is therefore unlinkable) but 
> http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf is a late
> draft and I believe this aspect is unchanged. Section 6.3.1.2 is one
> relevant part explaining that a _Bool must always be either 0 or 1:
> 
>     When any scalar value is converted to _Bool, the result is 0 if the
>     value compares equal to 0; otherwise, the result is 1.
> 
> Many of the other clauses dealing with Integers (e.g. 6.3.1.3.1) have
> had "other than _Bool" or some similar wording added to them since
> _Bool does indeed behave a little differently.
> 
> So I'm afraid I disagree with your statement, at least for C >= C99 (I
> can't recall if _Bool was in C89, but I think the answer is no).

I stand corrected: I've just checked it, and the conversion does indeed
happen on return -- at least gcc 5.2.1 -- even when, like in U-Boot
build files, c99 standard compliance is not specified.

If older GCCs (up to a point: how old a gcc are we wanting to
support?) also work this way too, the '!!' is indeed unneeded.

> Ian.

Amicalement,
-- 
Albert.


More information about the U-Boot mailing list