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

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

 



"Richard W.M. Jones" <rjones@xxxxxxxxxx> wrote:
> On Wed, Dec 17, 2008 at 09:08:36PM +0000, Daniel P. Berrange wrote:
>> Ok, if you want to re-post the HACKING file also mentioning that
>> 'bool' shouldn't be used in our public APIs & wire protocol,
>
> What's wrong with using it in the wire protocol?  XDR provides bool_t
> (as int) and converts 'bool' in the interface definition to bool_t.

It's good to know that from portability/correctness standpoints that
would work.  However, using a 32-bit "int" to transmit a single bit
of info is wasteful.  How about this clarification to HACKING?

diff --git a/HACKING b/HACKING
index ba03604..ca39d61 100644
--- a/HACKING
+++ b/HACKING
@@ -115,7 +115,10 @@ standard type like int32_t, uint32_t, uint64_t, etc.

 While using "bool" is good for readability, it comes with minor caveats:
  - Don't use "bool" in places where the type size must be constant across
-   all systems, like public interfaces and on-the-wire protocols.
+   all systems, like public interfaces and on-the-wire protocols.  Note
+   that it would be possible (albeit wasteful) to use "bool" in libvirt's
+   logical wire protocol, since XDR maps that to its lower-level bool_t
+   type, which *is* fixed-size.
  - Don't compare a bool variable against the literal, "true",
    since a value with a logical non-false value need not be "1".
    I.e., don't write "if (seen == true) ...".  Rather, write "if (seen)...".

--
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]