[pulseaudio-discuss] bools and bit-fields

Maarten Bosmans mkbosmans at gmail.com
Thu Aug 18 08:59:38 PDT 2011


2011/8/18 Rémi Denis-Courmont <remi at remlab.net>:
> 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).

Indeed, and we already use other headers from the C99 spec, like
inttypes.h extensively.

Moreover, in configure.ac we alread try to use C99 by calling
AC_PROG_CC_C99. If that macro is followed by a check for
ac_cv_prog_cc_c99 and error out if set to 'no'. Then we can just
assume _Bool is always present and use it.

Maarten

> --
> Rémi Denis-Courmont
> http://www.remlab.net/
> http://fi.linkedin.com/in/remidenis
> _______________________________________________
> pulseaudio-discuss mailing list
> pulseaudio-discuss at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/pulseaudio-discuss
>


More information about the pulseaudio-discuss mailing list