Changes between Version 10 and Version 11 of EFLWebKitCodingStyle


Ignore:
Timestamp:
Aug 13, 2012 7:31:17 PM (12 years ago)
Author:
rakuco@webkit.org
Comment:

Add a better explanation about the usage of !!s

Legend:

Unmodified
Added
Removed
Modified
  • EFLWebKitCodingStyle

    v10 v11  
    1010 * Use '''const''' keyword instead of '''#define''' when you define constant variable.
    1111 * Use NULL in public C headers instead of 0
    12  * Use '''double not operator(!!)''' when you modify or compare with a Eina Bool member variable which stores a value in a bit field.
     12 * Use a double negation '''(!!)''' when you modify or compare with a Eina Bool member variable which stores a value in a bit field.
    1313
    1414= Example =
     
    171171}}}
    172172
    173 == Use double not operator(!!) when you modify or compare with a Eina Bool member variable which stores a value in a bit field. ==
     173== Use a double negation when you modify or compare with a Eina Bool member variable which stores a value in a bit field. ==
     174`Eina_Bool` is an `unsigned char` typedef, which means one can in theory pass a value such as 3 or 42 to it. This can be problematic if one is storing an `Eina_Bool` in a bitfield, since only the last bit will be used. For example:
     175
     176{{{
     177#!cpp
     178struct MyStruct {
     179    Eina_Bool b : 1;
     180};
     181
     182void foo()
     183{
     184    Eina_Bool v1 = 2, v2 = 3;
     185    MyStruct s;
     186
     187    s.b = v1; // b is 0, since the least significant bit is 0 (2 == 10 in binary)
     188    s.b = v2; // b is 1, since the least significant bit is 1 (3 == 11 in binary)
     189}
     190}}}
     191
     192On the other hand, if an `Eina_Bool` is simply being obtained from some publicly-visible API and passed to another function that takes a `bool`, or if a bitfield is made from `bool`s instead of `Eina_Bool`s, this does not happen, since, according to the C++ standard, any value that is not zero, a null pointer or a null member pointer is converted to `true`.
     193
    174194=== Right ===
    175195{{{
    176196struct {
    177197    ...
    178     bool pageCache : 1;
     198    Eina_Bool pageCache : 1;
    179199    ...
    180200}