Date: Thu, 14 Nov 2024 00:49:33 GMT From: Ed Maste <emaste@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: fcd8e27dcf38 - stable/14 - style.9: be explicit about booleans in comparisons Message-ID: <202411140049.4AE0nXaJ026850@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/14 has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=fcd8e27dcf38532c4caf62f1610f389e5c9bd20c commit fcd8e27dcf38532c4caf62f1610f389e5c9bd20c Author: Ed Maste <emaste@FreeBSD.org> AuthorDate: 2021-05-27 15:25:32 +0000 Commit: Ed Maste <emaste@FreeBSD.org> CommitDate: 2024-11-14 00:49:21 +0000 style.9: be explicit about booleans in comparisons We prefer something like "if (count != 0)" over "if (count)" for non-boolean variables. This was implicit in examples, but was unclear for some new contributors. Attempt to clarify by providing a more explicit statement and example. Reviewed by: imp Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D30507 (cherry picked from commit 93f7a3023c3147d42dbe3dab58a5a70779587ea5) --- share/man/man9/style.9 | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/share/man/man9/style.9 b/share/man/man9/style.9 index 52292b896add..75daea47ca96 100644 --- a/share/man/man9/style.9 +++ b/share/man/man9/style.9 @@ -756,9 +756,10 @@ not: !(p = f()) .Ed .Pp -Do not use +Do not test without a comparison, or with unary .Ic \&! -for tests unless it is a boolean, e.g., use: +(except for booleans). +For example, use: .Bd -literal if (*p == '\e0') .Ed @@ -768,6 +769,16 @@ not: if (!*p) .Ed .Pp +Prefer: +.Bd -literal +if (count != 0) +.Ed +.Pp +over: +.Bd -literal +if (count) +.Ed +.Pp Routines returning .Vt "void *" should not have their return values cast
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202411140049.4AE0nXaJ026850>