[Spice-devel] bool or gboolean

Frediano Ziglio fziglio at redhat.com
Thu Feb 16 12:23:36 UTC 2017


> 
> On Wed, Feb 15, 2017 at 04:59:43PM +0000, Daniel P. Berrange wrote:
> > On Wed, Feb 15, 2017 at 11:39:32AM -0500, Frediano Ziglio wrote:
> > > Hi,
> > >   question was raised recently on the ML and IRC.
> > > 
> > > Some time ago we decided to use gboolean but some of us would like
> > > to discuss again.
> > > 
> > > As any style changes there's no right or wrong, mainly personal
> > > opinions but I think consistency is quite important.
> > > 
> > > Some consideration (feel free to add/remove/comment)
> > > - gboolean is more used in the code (about 76%)
> > > - TRUE/FALSE are more used (96%)
> > > - bool is C99 convention, defined in stdbool.h
> > > - using gcc the bool type is a bit different from gboolean
> > >   (which basically is an int) catching some problems as
> > >   warnings (like cast between different function pointers
> > >   using bool instead of gboolean/int)
> > > - bool is easier to write (OT: and my vim is more happy too)
> > 
> > As noted above gboolean & bool are different types, in fact they
> > are different sizes too (4 bytes vs 1 byte).
> > 
> > If you're using glib2, you'll find various places where it wants
> > callbacks which have a gboolean return value, or parameters. You
> > can't pass in a callback which uses bool, as that's not type
> > compatible. So no matter what, you'll always need to use gboolean
> > in some portion of the code, even if you would rather have bool.
> 
> NB: There is one place in the code with such a constraint already, which
> is the interfacing with libpjeg:
> 
> static boolean dest_mgr_empty_output_buffer(j_compress_ptr cinfo)
> static boolean empty_mem_output_buffer(j_compress_ptr cinfo)
> 
> this 'boolean' is equivalent to an int, and can't be changed to bool.
> 
> Christophe
> 

I also found that spice-common uses some bool.

Maybe adding a new spice_bool type (clearly a joke)!

Sometimes I miss Byte and Boolean from the old good Pascal.

I still prefer bool, true and false, just apparently we can't get
rid of all boolean type definitions, like this code:

   strchr("foo", 'f')[0] = 1;

will compile perfectly and crash in C (this will fail to even
compile with C++).

Some weeks ago I found some K&R C style declaration!

Frediano


More information about the Spice-devel mailing list