On Thu, Feb 6, 2014 at 7:08 AM, Gerhard Sittig <[email protected]> wrote: > 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".
Seems to be true at least for C99: http://stackoverflow.com/a/8617111/251248 > 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. In any case, we will be converting the driver's get/set functions to use bools (not sure if we want to go as far as doing the same for gpio_get/set_value()). This should settle the issue. Alex. -- 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
