Date: Tue, 12 Nov 2024 17:25:46 GMT From: Ed Maste <emaste@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: 93f7a3023c31 - main - style.9: be explicit about booleans in comparisons Message-ID: <202411121725.4ACHPkjP033764@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch main has been updated by emaste: URL: https://cgit.FreeBSD.org/src/commit/?id=93f7a3023c3147d42dbe3dab58a5a70779587ea5 commit 93f7a3023c3147d42dbe3dab58a5a70779587ea5 Author: Ed Maste <emaste@FreeBSD.org> AuthorDate: 2021-05-27 15:25:32 +0000 Commit: Ed Maste <emaste@FreeBSD.org> CommitDate: 2024-11-12 17:25:28 +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 --- 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 69561e3e1e73..9bf30370a374 100644 --- a/share/man/man9/style.9 +++ b/share/man/man9/style.9 @@ -746,9 +746,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 @@ -758,6 +759,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?202411121725.4ACHPkjP033764>