[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH 2/5] CODING_STYLE: add C type rules
From: |
Blue Swirl |
Subject: |
Re: [Qemu-devel] [PATCH 2/5] CODING_STYLE: add C type rules |
Date: |
Tue, 17 Aug 2010 17:56:03 +0000 |
On Tue, Aug 17, 2010 at 8:09 AM, Jes Sorensen <address@hidden> 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 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++;
> if (foo == true)....
It's already in use. Could you write a replacement rule which forbids
any new bool use and welcomes patches to remove any existing cases?
> 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 :(
Only on Win64 (http://technet.microsoft.com/en-us/library/bb496995.aspx)
but we don't support that.
We could add something like traditional "don't mix int and pointer
sizes" and not require intptr_t in place of longs.
- [Qemu-devel] [PATCH 2/5] CODING_STYLE: add C type rules, Blue Swirl, 2010/08/12
- [Qemu-devel] Re: [PATCH 2/5] CODING_STYLE: add C type rules, Blue Swirl, 2010/08/13
- Re: [Qemu-devel] [PATCH 2/5] CODING_STYLE: add C type rules, Jes Sorensen, 2010/08/17
- Re: [Qemu-devel] [PATCH 2/5] CODING_STYLE: add C type rules,
Blue Swirl <=
- Re: [Qemu-devel] [PATCH 2/5] CODING_STYLE: add C type rules, malc, 2010/08/17
- Re: [Qemu-devel] [PATCH 2/5] CODING_STYLE: add C type rules, Jes Sorensen, 2010/08/17
- Re: [Qemu-devel] [PATCH 2/5] CODING_STYLE: add C type rules, malc, 2010/08/17
- Re: [Qemu-devel] [PATCH 2/5] CODING_STYLE: add C type rules, Jes Sorensen, 2010/08/17
- Re: [Qemu-devel] [PATCH 2/5] CODING_STYLE: add C type rules, Anthony Liguori, 2010/08/17
- Re: [Qemu-devel] [PATCH 2/5] CODING_STYLE: add C type rules, malc, 2010/08/17
Re: [Qemu-devel] [PATCH 2/5] CODING_STYLE: add C type rules, Richard Henderson, 2010/08/17