All of lore.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: Jes Sorensen <Jes.Sorensen@redhat.com>
Cc: Blue Swirl <blauwirbel@gmail.com>, qemu-devel <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH 2/5] CODING_STYLE: add C type rules
Date: Wed, 18 Aug 2010 19:44:13 +0300	[thread overview]
Message-ID: <4C6C0DDD.9090001@redhat.com> (raw)
In-Reply-To: <4C6A43B5.40809@redhat.com>

  On 08/17/2010 11:09 AM, Jes Sorensen wrote:
> On 08/12/10 19:50, Blue Swirl wrote:
>> +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.
>> + - 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)...".
> I'd strongly discourage the use of bool in any code. It doesn't provide
> anything guarantees

It's actually better than int:

      int flag = word & BIT;

can lose the BIT if it is outside the range of an int, whereas

     bool flag = word & BIT;

will be true if BIT is set.  Not to mention the improved readability 
(which appears to be a downside to C fans).

> and you are not sure about the size of it. Using int
> is safer. IMHO bool is one of the worse examples of changes to the C
> standard :(
>
> bool foo = false;
> foo++;

What's incrementing a bool supposed to mean?  Even more true?

> if (foo == true)....

As it happens, this will succeed.

> The other thing that might be worth mentioning in the int/long section
> is that long is complicated in broken development environments such as
> Windows where it is only 32 bit :(

It's only complicated if you assume sizeof(long) == sizeof(void *).  
While we're used to it from Linux, all you need is s/long/intptr_t/ and 
you're all set.

-- 
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.

      parent reply	other threads:[~2010-08-18 16:44 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-12 17:50 [Qemu-devel] [PATCH 2/5] CODING_STYLE: add C type rules Blue Swirl
2010-08-13 19:37 ` [Qemu-devel] " Blue Swirl
2010-08-17  8:09 ` [Qemu-devel] " Jes Sorensen
2010-08-17 17:56   ` Blue Swirl
2010-08-17 18:55     ` malc
2010-08-17 19:23       ` Jes Sorensen
2010-08-17 19:24         ` malc
2010-08-17 19:43           ` Jes Sorensen
2010-08-17 20:29             ` Anthony Liguori
2010-08-17 20:33             ` malc
2010-08-17 18:39   ` Richard Henderson
2010-08-17 19:15     ` Jes Sorensen
2010-08-18 16:46       ` Avi Kivity
2010-08-19  7:58         ` Jes Sorensen
2010-08-19  8:10           ` Avi Kivity
2010-08-19  8:17             ` Jes Sorensen
2010-08-19 12:24               ` Avi Kivity
2010-08-19 12:52                 ` malc
2010-08-19 12:59                   ` Avi Kivity
2010-08-18  8:35     ` [Qemu-devel] " Paolo Bonzini
2010-08-18  8:58       ` Jes Sorensen
2010-08-18 10:30       ` Kevin Wolf
2010-08-18 13:57         ` Paolo Bonzini
2010-08-18 16:55           ` Avi Kivity
2010-08-19  7:51             ` Paolo Bonzini
2010-08-19  8:12               ` Avi Kivity
2010-08-18 16:44   ` Avi Kivity [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4C6C0DDD.9090001@redhat.com \
    --to=avi@redhat.com \
    --cc=Jes.Sorensen@redhat.com \
    --cc=blauwirbel@gmail.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.