diff options
author | Richard Braun <rbraun@sceen.net> | 2017-07-14 11:46:44 +0200 |
---|---|---|
committer | Richard Braun <rbraun@sceen.net> | 2017-07-14 11:47:25 +0200 |
commit | adcae3076edee5ed24cb06f4328f88cfa5e8998a (patch) | |
tree | 8c080afe40bbbab6a3e74c7fde532219b9deb876 | |
parent | ff184c2554bdc4ddd5efafb4d1d2dd5a8dc2f116 (diff) |
doc/style(9): relax boolean coercion rules about pointers
Friends can be convincing, and I do have an open mind, don't I ?
-rw-r--r-- | doc/style.9.txt | 19 |
1 files changed, 4 insertions, 15 deletions
diff --git a/doc/style.9.txt b/doc/style.9.txt index 8d87efb6..72095671 100644 --- a/doc/style.9.txt +++ b/doc/style.9.txt @@ -613,19 +613,8 @@ the macro used to declare an array again in the iteration code. Boolean Coercion ~~~~~~~~~~~~~~~~ -Boolean coercion is forbidden by default, especially on pointers. Always -explicitely compare pointers to NULL and integers to 0. For example : - -[source,c] --------------------------------------------------------------------------------- -/* Read "if ptr is not invalid and if ptr and ref are equal" */ -if ((ptr != NULL) && (memcmp(ptr, ref, sizeof(*ptr)) == 0)) { - do_something(); -} --------------------------------------------------------------------------------- - -The main exception to this rule is error codes, which developers are -encouraged to use as boolean values. Here is an example : +Boolean coercion is forbidden by default. It is only allowed when +checking error codes and pointers. For example : [source,c] -------------------------------------------------------------------------------- @@ -642,8 +631,8 @@ if (error) { } -------------------------------------------------------------------------------- -The other exception is the historical use of the *int* type, rather than -the C99 *bool* type, for boolean values. +There are historical uses of the *int* type for boolean values, but all of +them should be converted to the C99 *bool* type. Side effects and conditions ~~~~~~~~~~~~~~~~~~~~~~~~~~~ |