Re: [LAD] Mixed boolean & numbers

From: David Robillard <d@email-addr-hidden>
Date: Thu Sep 01 2016 - 04:28:45 EEST

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.

-- 
dr
_______________________________________________
Linux-audio-dev mailing list
Linux-audio-dev@email-addr-hidden
http://lists.linuxaudio.org/listinfo/linux-audio-dev
Received on Thu Sep 1 08:15:01 2016

This archive was generated by hypermail 2.1.8 : Thu Sep 01 2016 - 08:15:01 EEST