On Mon, May 11, 2009 at 3:12 PM, Lennart Poettering<lennart at poettering.net> wrote: > On Mon, 11.05.09 12:56, Felipe Contreras (felipe.contreras at gmail.com) wrote: > >> >> On Sat, May 9, 2009 at 3:14 PM, Lennart Poettering >> <lennart at poettering.net> wrote: >> > On Sat, 09.05.09 12:50, Felipe Contreras (felipe.contreras at gmail.com) wrote: >> > >> >> > pa_bool_t is used internally only. In the public API we only expose >> >> > ints. pa_bool_t is defined as _Bool on C99 and int on other >> >> > compilers. This discrepancy should not be visible to outside due to >> >> > ABI stability issues. >> >> >> >> Minor comment; if you include stdbool.h you can use 'bool' which IMHO >> >> is less ugly than _Bool. And I wonder what's the point of pa_bool_t... >> >> if the compiler doesn't have stdbool.h, then just define 'bool' as you >> >> would define pa_bool_t. >> > >> > There's not much difference between _Bool, and bool. Both are C99. >> >> Nope, the only difference is that 'bool' looks nicer :) >> >> > I guess 10 years after C99 it might be possible to drop C89 >> > support. But uh, the API uses int for all bools and we should stick to >> > it for now. >> >> This is what I meant: >> >> #if HAVE_STDBOOL_H >> #include <stdbool.h> >> #else >> typedef unsigned char bool >> #endif > > Firstly that would require including config.h from public header > files which we don't do. > > But more importantly this will break ABI when folks switch between C89 > and C99. > > Also there are lots of subtle differences between 'unsigned > char'/'int' and 'bool'. > > sizof(bool) is usually sizeof(int). However sizeof(bool) is != > sizeof(unsigned char). In a struct defining 'bool foo:1' works fine > and then allows assignment of 1/0. However in a struct 'int foo:1' > allows assignment of -1/0 only. > > Internally we actually use a definition like you suggested, but we > don't want to push that into the ABI and hence trigger breakage > there. Our definition is like this: > > #ifdef HAVE_STD_BOOL > typedef _Bool pa_bool_t; > #else > typedef int pa_bool_t; > #endif You said pa_bool_t is only internal, so it's safe to do: #if HAVE_STDBOOL_H #include <stdbool.h> #else typedef int bool #endif And s/pa_bool_t/bool/ If you have C99, pa_bool_t = _Bool, bool = _Bool If you don't: pa_bool_t = int, bool = int -- Felipe Contreras