From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=59197 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OllkU-0001xV-Tq for qemu-devel@nongnu.org; Wed, 18 Aug 2010 12:44:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OllkT-0007fE-Oz for qemu-devel@nongnu.org; Wed, 18 Aug 2010 12:44:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58317) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OllkT-0007et-Fn for qemu-devel@nongnu.org; Wed, 18 Aug 2010 12:44:21 -0400 Message-ID: <4C6C0DDD.9090001@redhat.com> Date: Wed, 18 Aug 2010 19:44:13 +0300 From: Avi Kivity MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH 2/5] CODING_STYLE: add C type rules References: <4C6A43B5.40809@redhat.com> In-Reply-To: <4C6A43B5.40809@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Jes Sorensen Cc: Blue Swirl , qemu-devel 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.