From nobody Mon Feb 9 06:50:22 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1557398637; cv=none; d=zoho.com; s=zohoarc; b=RpOGdNBb9u90Yei0d1Sk4d+5a96PNSD0wUmBQS+qbRemJzv459atNuddiUXr2E0s9SQWyuqT8KbJfD02njusIGm5w8cj9tNa3mEADapkMxDKWfXL7wY7e4H+O/BR6Lb/acG8tsjOVGh+AB9mAqewDlknnDa1XhQ7cF0we9LyaTg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557398637; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=qksLy6KAyikFw2olbx2vAghJl8SMjccC48iB0jEhx4c=; b=DOBS8DssH7wvhdUZNZMymXd8QuWy/gnWK5fu91z9kua0fXnZDZpR8kBnaW/Qdv40hw6Gv86oiqDaVrfRTEb58cLPdLqyik64o0vdlktF7WtNJIAdIzpd4ZauuuVIO9Jg9qSpCo9+4n78WMvhgDVjlyqZUlTwwV5pSaRI+TOtjIE= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1557398637147840.6277551017054; Thu, 9 May 2019 03:43:57 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 62739309B141; Thu, 9 May 2019 10:43:55 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3A6581001E74; Thu, 9 May 2019 10:43:55 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id ED86B41F3D; Thu, 9 May 2019 10:43:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x49Ahd0p029929 for ; Thu, 9 May 2019 06:43:39 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8E34563C31; Thu, 9 May 2019 10:43:39 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.229]) by smtp.corp.redhat.com (Postfix) with ESMTP id 17F2961786 for ; Thu, 9 May 2019 10:43:38 +0000 (UTC) From: Peter Krempa To: libvir-list@redhat.com Date: Thu, 9 May 2019 12:43:33 +0200 Message-Id: <468fe5c3af5b52f3f23e60815f0a284e43466b41.1557398401.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/3] docs: hacking: Add good practices for shortening conditional expressions X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Thu, 09 May 2019 10:43:55 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Document that checking if a integer is (non-)zero should (not must) avoid the shortened form that C allows as it may confuse readers into overlooking the other possible values which might be interresting to handle. While pointers have distinct values from the point of view of the code we only care whether it's non-NULL and thus it's documented it's okay to shorten those. Signed-off-by: Peter Krempa --- docs/hacking.html.in | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/docs/hacking.html.in b/docs/hacking.html.in index 081d793360..a2800853ef 100644 --- a/docs/hacking.html.in +++ b/docs/hacking.html.in @@ -826,6 +826,28 @@ } +

Conditional expressions

+

For readability reasons new code should avoid shortening comparis= ons + to 0 for numeric types. Boolean and pointer comparisions may be + shortened. All long forms are okay: +

+
+   virFooPtr foos =3D NULL;
+   size nfoos =3D 0;
+   bool hasFoos =3D false;
+
+GOOD:
+    if (!foos)
+    if (!hasFoos)
+    if (nfoos =3D=3D 0)
+    if (foos =3D=3D NULL)
+    if (hasFoos =3D=3D true)
+
+BAD:
+    if (!nfoos)
+    if (foos)
+
+

Preprocessor

Macros defined with an ALL_CAPS name should generally be --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list