diff options
-rw-r--r-- | doc/style.9.txt | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/doc/style.9.txt b/doc/style.9.txt index 30322f32..c61bc777 100644 --- a/doc/style.9.txt +++ b/doc/style.9.txt @@ -613,7 +613,9 @@ the macro used to declare an array again in the iteration code. Boolean Coercion ~~~~~~~~~~~~~~~~ -Boolean coercion is forbidden by default. It is only allowed when +Boolean coercion should only be used when the resulting text is semantically +valid, i.e. it can be understood that the expression is either true, or false. + checking error codes and pointers. For example : [source,c] @@ -622,6 +624,7 @@ int error; error = do_something(); +/* Valid */ if (error) { if (error != ERROR_AGAIN) { printf("unexpected error\n"); @@ -629,6 +632,18 @@ if (error) { return error; } + +int color; + +color = get_color(); + +/* Invalid */ +if (!color) { + print_black(); +} else if (color == 1) { + print_red(); +} + -------------------------------------------------------------------------------- There are historical uses of the *int* type for boolean values, but all of |