On Wed, Feb 05, 2014 at 14:14 +0100, Linus Walleij wrote:
> 
> The generic GPIO would return 0 for low generic GPIO, and
> something != 0 for high GPIO. Let's make this sane by clamping
> the returned value to [0,1].
>  
> [ ... ]
>  
> -     return bgc->read_reg(bgc->reg_dat) & bgc->pin2mask(bgc, gpio);
> +     return !!(bgc->read_reg(bgc->reg_dat) & bgc->pin2mask(bgc, gpio));

I've asked this before, may be too picky, but certainly want to
make sure.  Is any language lawyer around? :)  Would be nice to
get a definitive answer on this, before the pattern gets spread
even more and still does not what callers expect.

Is there a guarantee that "!0" will result in "1", and not "-1"
or any other non-zero implementation defined bit pattern?  I
always thought that one had to write "val ? 1 : 0", or else the
result may just be another kind of "zero or non-zero".

Remember that the return data type is int.  For bool you would
get exactly "true" and "false", but for int I would not be sure,
and would rather err to the safe side.


virtually yours
Gerhard Sittig
-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr. 5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: [email protected]
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to