Re: [libvirt] proposal: allow use of "bool": HACKING: discuss C types

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Dec 17, 2008 at 01:29:02PM +0100, Jim Meyering wrote:
> "Daniel P. Berrange" <berrange@xxxxxxxxxx> wrote:
> > On Fri, Dec 12, 2008 at 09:58:32AM +0100, Jim Meyering wrote:
> >> I propose to allow (encourage, even) the use of the standard C99 type,
> >> bool, in libvirt, but not in public interfaces[1].  There are already
> >> uses in cgroup.c and xmlrpc.c, as well as those in the gnulib "c-ctype.h"
> >> header which is included from many of libvirt's .c files.
> >>
> >> The motivation is to make the code as readable as possible.
> >> When you see the declaration of an "int" variable, member, or function,
> >> that type gives you no clue whether it is used as a boolean.  If you
> >> see a few uses that treat it as boolean, that's still no guarantee,
> >> and it may be non-trivial to ensure that there isn't some non-boolean
> >> value with a special meaning.
> >>
> >> However, if you see a "bool" variable, you do have that guarantee.
> >
> > I don't particularly like the idea of using the bool type
> >
> >  - No system header files use it
> 
> Of course.  Can't use it there for the same reason that we wouldn't
> use it in libvirt's own public interfaces, as I explained.  But public
> interfaces make up such a small fraction of the code in question that
> it'd be a shame to impose its restrictions on all the rest.
> 
> >  - Library header files which use a boolean type have nearly all defined
> >    their own custom bool types, not using stdbool.h and there's no guarentee
> >    that stdbool's idea of 'true' matches the other apps'
> 
> This is the same fundamental restriction.
> "bool" cannot be used in public headers.
> 
> >  - We don't use it in the public API, or on the wire for the remote
> >    protocol, since it has undefined size.
> 
> Same point.
> 
> >  - The GNULIB bool emulation is unable to provide equivlance between
> >    C's idea of true (any non-zero value) and the defined 'true'
> >    constant (whose value is 1)
> 
> That sounds scary, but isn't an issue in practice.
> The uses of "true" and "false" are typically only for
> initialization.  IMHO, one should never compare a bool-declared
> variable to "true" or "false".

Ok, if you want to re-post the HACKING file also mentioning that
'bool' shouldn't be used in our public APIs & wire protocol,
and that 'true' / 'false' should only be used for initialization
I'm fine with the rest of the docs.

Daniel
-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]