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 |
| 178 | struct MyStruct { |
| 179 | Eina_Bool b : 1; |
| 180 | }; |
| 181 | |
| 182 | void 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 | |
| 192 | On 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 | |