[Spice-devel] bool or gboolean

Daniel P. Berrange berrange at redhat.com
Wed Feb 15 16:59:43 UTC 2017


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.

Thus if consistency is the goal, then gboolean is the winner as
you're more likely to be able to kill off all uses of bool, than
be able to kill off all uses of gboolean.


Regards,
Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://entangle-photo.org       -o-    http://search.cpan.org/~danberr/ :|


More information about the Spice-devel mailing list