bools and bit-fields

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Le jeudi 18 ao?t 2011 17:53:43 Arun Raghavan, vous avez ?crit :
> The condition in the if statement may evaluate to false if pa_bool_t is
> typedef'ed to a signed type (it definitely is if you don't have
> stdbool.h, not sure if _Bool is a signed type or not).

The ISO C standard requires that _Bool bit fields with non-zero width can 
store _and_ *compare* to 0 and 1.

> This happens
> because it's a single bit field and thus when the msb (the only bit) is
> set to 1 it is interpreted as -1.

Right. So pa_bool_t should be typedef'd to 'unsigned' rather than 'int' 
wherever HAVE_STD_BOOL is not defined.

Then again, <stdbool.h> is a non-optional part of the C standard. Defining 
your own boolean type feels very 90's (and indeed error-prone).

-- 
R?mi Denis-Courmont
http://www.remlab.net/
http://fi.linkedin.com/in/remidenis


[Index of Archives]     [Linux Audio Users]     [AMD Graphics]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux