diff options
author | Richard Braun <rbraun@sceen.net> | 2017-07-30 18:35:34 +0200 |
---|---|---|
committer | Richard Braun <rbraun@sceen.net> | 2017-07-30 18:36:47 +0200 |
commit | 9bb3b8ca7f4a6d9ff33244a98673b3ffe762d6c2 (patch) | |
tree | bded8780877907e12d758851a055c9f0b74a325d | |
parent | b9411198e3853793b4f9cf10af65587875f5f478 (diff) |
doc/style(9): relax boolean coercion rules even more
-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 |