[ovs-dev] [PATCH] lib/flow.h: Improve struct miniflow comment and definition.

Gurucharan Shetty shettyg at nicira.com
Wed Aug 27 15:54:47 UTC 2014


On Tue, Aug 26, 2014 at 4:08 PM, Ben Pfaff <blp at nicira.com> wrote:
> On Tue, Aug 26, 2014 at 04:04:09PM -0700, Jarno Rajahalme wrote:
>>
>> On Aug 26, 2014, at 3:53 PM, Ben Pfaff <blp at nicira.com> wrote:
>>
>> > On Tue, Aug 26, 2014 at 03:42:33PM -0700, Jarno Rajahalme wrote:
>> >> Finally, use change the storage type of 'values_inline' to uint8_t, as
>> >> uint64_t looks kind of wide for a boolean, even though we intend the
>> >> bit be carved out from the uint64_t where 'map' resides.
>> >
>> > It can't be type "bool"?
>>
>> From CodingStyle:
>>
>>   Declare bit-fields to be type "unsigned int" or "signed int".  Do
>> *not* declare bit-fields of type "int": C89 allows these to be either
>> signed or unsigned according to the compiler's whim.  (A 1-bit
>> bit-field of type "int" may have a range of -1...0!)  Do not declare
>> bit-fields of type _Bool or enum or any other type, because these are
>> not portable.
>>
>> :-)
>
> This was important when we supported C89 compilers that did not have
> native _Bool (bool), but I think that it is obsolete now, because all
> of the compilers we support have C99 implementations good enough to
> have native _Bool.
>
> Let's find out and update CodingStyle if so.
>
> Guru: does MSVC allow "bool" bit-fields?  I assume so but it's worth a
> test.

You mean something like this, right?  If so, it does work.
#include <stdio.h>
#include <stdbool.h>

struct test {
bool a:1;
bool b:1;
};

main()
{
struct test t;
t.a = 1;
t.b = 0;

printf("%d %d", t.a, t.b);
}


>
> Thanks,
>
> Ben.



More information about the dev mailing list