[Spice-devel] bool or gboolean

Christophe Fergeau cfergeau at redhat.com
Thu Feb 16 10:51:43 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20170216/21abd30c/attachment-0001.sig>


More information about the Spice-devel mailing list