[pulseaudio-discuss] bools and bit-fields

Arun Raghavan arun.raghavan at collabora.co.uk
Thu Aug 18 21:16:06 PDT 2011


On Thu, 2011-08-18 at 17:59 +0200, Maarten Bosmans wrote:
> 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.

Fair enough. If there are no objections, I'll remove the !HAVE_STD_BOOL
condition from the headers post 1.0.

-- Arun



More information about the pulseaudio-discuss mailing list