[LAD] Mixed boolean & numbers

Will J Godfrey WillGodfrey at musically.me.uk
Fri Sep 2 16:27:56 UTC 2016


On Wed, 31 Aug 2016 21:28:45 -0400
David Robillard <d at drobilla.net> wrote:

> On Sat, 2016-08-27 at 16:49 +0100, Will Godfrey wrote:
> > I'm finding quite a lot of occasions where variables defined as 'bool' are
> > sometimes being set with true or false and other times 0 or 1. On one occasion
> > there is something like x = n + {boolean variable}
> > 
> > This last one seems quite unsafe to me as I didn't think the actual value of
> > true and false was guaranteed.
> > 
> > Am I being overly cautious or should I change them all to one form or the other?  
> 
> This is fine.  The C/C++ standards guarantee that a bool, when converted
> to an integer, is 1 or 0 (the pedantically correct way of saying this
> depends on which standard/revision, but effectively that sums it up).
> 
> It's pretty convenient/elegant at times.  Personally, I exploit it when
> that's the case, but be more explicit if it has potential to be
> confusing.

Thanks again for the info.


-- 
It wasn't me! (Well actually, it probably was)

... the hard part is not dodging what life throws at you,
but trying to catch the good bits.


More information about the Linux-audio-dev mailing list