From patchwork Mon Aug 4 09:19:45 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gonglei (Arei)" X-Patchwork-Id: 376202 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id CBD96140090 for ; Mon, 4 Aug 2014 19:23:48 +1000 (EST) Received: from localhost ([::1]:51187 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XEEUc-0003ZN-Vi for incoming@patchwork.ozlabs.org; Mon, 04 Aug 2014 05:23:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50649) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XEES0-0007cN-3n for qemu-devel@nongnu.org; Mon, 04 Aug 2014 05:21:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XEERu-0000lq-Qb for qemu-devel@nongnu.org; Mon, 04 Aug 2014 05:21:04 -0400 Received: from szxga01-in.huawei.com ([119.145.14.64]:59917) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XEERu-0000kQ-2c for qemu-devel@nongnu.org; Mon, 04 Aug 2014 05:20:58 -0400 Received: from 172.24.2.119 (EHLO szxeml424-hub.china.huawei.com) ([172.24.2.119]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id BZQ10304; Mon, 04 Aug 2014 17:20:11 +0800 (CST) Received: from localhost (10.177.19.102) by szxeml424-hub.china.huawei.com (10.82.67.163) with Microsoft SMTP Server id 14.3.158.1; Mon, 4 Aug 2014 17:20:01 +0800 From: To: Date: Mon, 4 Aug 2014 17:19:45 +0800 Message-ID: <1407143992-9248-2-git-send-email-arei.gonglei@huawei.com> X-Mailer: git-send-email 1.7.3.1.msysgit.0 In-Reply-To: <1407143992-9248-1-git-send-email-arei.gonglei@huawei.com> References: <1407143992-9248-1-git-send-email-arei.gonglei@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.177.19.102] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 119.145.14.64 Cc: peter.maydell@linaro.org, peter.crosthwaite@xilinx.com, weidong.huang@huawei.com, stefanha@redhat.com, mst@redhat.com, marcel.a@redhat.com, luonengjun@huawei.com, armbru@redhat.com, lcapitulino@redhat.com, Gonglei , av1474@comtv.ru, kraxel@redhat.com, aliguori@amazon.com, imammedo@redhat.com, dmitry@daynix.com, pbonzini@redhat.com, peter.huangpeng@huawei.com, afaerber@suse.de, dgilbert@redhat.com Subject: [Qemu-devel] [PATCH v4 1/8] CODING_STYLE: Section about conditional statement X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Gonglei Yoda conditions lack readability, and QEMU has a strict compiler configuration for checking a common mistake like "if (dev = NULL)". Make it a written rule. Signed-off-by: Gonglei Reviewed-by: Eric Blake --- CODING_STYLE | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CODING_STYLE b/CODING_STYLE index 4280945..d46cfa5 100644 --- a/CODING_STYLE +++ b/CODING_STYLE @@ -91,3 +91,17 @@ Mixed declarations (interleaving statements and declarations within blocks) are not allowed; declarations should be at the beginning of blocks. In other words, the code should not generate warnings if using GCC's -Wdeclaration-after-statement option. + +6. Conditional statements + +When comparing a variable for (in)equality with a constant, list the +constant on the right, as in: + +if (a == 1) { + /* Reads like: "If a equals 1" */ + do_something(); +} + +Rationale: Yoda conditions (as in 'if (1 == a)') are awkward to read. +Besides, good compilers already warn users when '==' is mis-typed as '=', +even when the constant is on the right.