1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-22 17:35:35 +03:00

some CODING_STYLE additions

This commit is contained in:
Lennart Poettering 2019-06-25 09:59:24 +02:00 committed by Zbigniew Jędrzejewski-Szmek
parent 9a02707561
commit b5bd7a29f9

View File

@ -201,6 +201,19 @@ title: Coding Style
array. In that case use STRLEN, which evaluates to a static constant and
doesn't force the compiler to create a VLA.
- Please use C's downgrade-to-bool feature only for expressions that are
actually booleans (or "boolean-like"), and not for variables that are really
numeric. Specifically, if you have an `int b` and it's only used in a boolean
sense, by all means check its state with `if (b) …` — but if `b` can actually
have more than two semantic values, and you want to compare for non-zero,
then please write that explicity with `if (b != 0) …`. This helps readability
as the value range and semantical behaviour is directly clear from the
condition check. As a special addition: when dealing with pointers which you
want to check for non-NULL-ness, you may also use downgrade-to-bool feature.
- Please do not use yoda comparisons, i.e. please prefer the more readable `if
(a == 7)` over the less readable `if (7 == a)`.
## Destructors
- The destructors always deregister the object from the next bigger object, not