From: Lennart Poettering Date: Tue, 25 Jun 2019 07:59:24 +0000 (+0200) Subject: some CODING_STYLE additions X-Git-Tag: v243~352 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b5bd7a29f99b776b73899fe0e42c426de0f859a8;p=platform%2Fupstream%2Fsystemd.git some CODING_STYLE additions --- diff --git a/docs/CODING_STYLE.md b/docs/CODING_STYLE.md index d945f8c..517bd2b 100644 --- a/docs/CODING_STYLE.md +++ b/docs/CODING_STYLE.md @@ -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