From patchwork Tue Aug 22 15:50:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 715759 Delivered-To: patch@linaro.org Received: by 2002:adf:f747:0:b0:317:ecd7:513f with SMTP id z7csp337676wrp; Tue, 22 Aug 2023 08:50:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFXbPs1n0+uHbGxW1I3k7o2BOIPitWrgQuypb5ISst0JYKvVBUnTNPzoTTru8btapTsUPGW X-Received: by 2002:a05:620a:4056:b0:76d:312a:e89a with SMTP id i22-20020a05620a405600b0076d312ae89amr12640126qko.19.1692719459517; Tue, 22 Aug 2023 08:50:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692719459; cv=none; d=google.com; s=arc-20160816; b=BmmbsOUOYyGGrxBV8go4eEXUNQeNw5XWNTO+RcIsVoTjkZ+3khAzJyuhQOMHp9qRTc RMXG9anEEr2GNp92LrKOEL+t9aUz46uaG8a5fj/Yb1U47J3rBfKgbkUmR1WXKvk/2/IM oNDIu4eTlJgY8ZEQ3Q4Hu+vPoSoSTt+Ew6bCioUPDNNBikBfMblGmCHe0et6d7y4RjXH bkoMatfPgcl1NkrzB+WjmY+eQU/GVb6vkbbOr7/QbArhQuWDmGH1QtcPcq4vHUcGIrOK VraDE2BrtXLoe46N05oTcnHlJABRXIBTPGaYlB+CrpqwVpQ9LHzbi38INQgMFrNMTDr3 oDAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=Ty+MUkk4NoppjREySXRnsnBpbVPnIcQrATnyM/78euY=; fh=v0Ip2JRmLttfOhClOhWtZrk9eQVaD8BiKbUYHbhu4Ck=; b=a8FUP68BEkDdQ2i7hjkM3rBphvgicZdRacKexbNX3yL4YtJXtFk/2JkIMmxau6vPwW 9BqKy6ynX4eCP0dA9O4kwbQ8C0U7Nxgtkw/cEmCH0Z/ZKn27NAtR5Wm713aHiKGHE4Vb 76O3fxwERarpldfxHMCBULWTbMGC9lyZzFr9bGS97n/4s/tXEXx34ybYzcwu+xJgbyni eOM/STo4PbCZQaDLX/GHGnK25g3u0dYEoCkyimv1GtldhwDRjNMPuHmzei9EwcfZPhQw HZt7+icenBTmyFHfYR9eVSEwIiC/bTQVLQzQErn39phcg3YvAFqOpCPZv5btKAGrOd3W +iaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="OljoUuv/"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id ee26-20020a05620a801a00b00767ce544623si1404948qkb.26.2023.08.22.08.50.59 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 22 Aug 2023 08:50:59 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="OljoUuv/"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qYTe5-0006Ig-Op; Tue, 22 Aug 2023 11:50:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qYTe4-0006IH-91 for qemu-devel@nongnu.org; Tue, 22 Aug 2023 11:50:16 -0400 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qYTe2-0002LT-3M for qemu-devel@nongnu.org; Tue, 22 Aug 2023 11:50:16 -0400 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-31adc5c899fso4302813f8f.2 for ; Tue, 22 Aug 2023 08:50:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692719412; x=1693324212; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Ty+MUkk4NoppjREySXRnsnBpbVPnIcQrATnyM/78euY=; b=OljoUuv/8zK0BBV+H8uPSYrDt7AhB6bnmyNCoSXSNSOmLdKLNXGpMDVys7XXdsNhTz gK8Qt03Zfby+ISpvkJ8HqZWIW2R5kpUXCoen8tUQfYc8xsD3jfPZVO3+yvJNGdWwJvQr bZODCsUcIUod2nnB8G0W3vAhkXhMoykI5Gu83ueNG4i/pNeX7B2tuPfz0hCGwUDbEj5+ Yvkex9ZlY6rRc8j2z9jzzdkgEWiUHIDsslrQQoSMgqEFrChXaiATcbiJ7ANhDx2fsR2g 2Slc+nL6Uk8FB1kIgEMRxd4x386/MysnrjqqnSqwJMGUfWxn856ppvf6tPkRCZI7nNwz QqWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692719412; x=1693324212; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Ty+MUkk4NoppjREySXRnsnBpbVPnIcQrATnyM/78euY=; b=OGY4hJhfEF9+MwqjjiTiHGiwm4RJNr+njio7y0RrzoLtv9VtWv9GAuB3OcVSKhUzI2 shX6g1kZVEsmLtcvlTEbr01Jt/zAg02JDI4znc/h7y/UkmS2eeeaDkYtKsLTgW4MEpyL KaDHZM0tbMKeWaFbY30uIrsSq+QhU15MTZ2OuFvnBU+uv8NLCRxGu3HQ2WqUdi5YFGit 0+naLh6UHjApwjTZUVP6ki+L/6vSxQbeTXA6MducOw6Mi1Wrax3MkPxZMHkxFSgepPF5 X1c45wvBmkwmfOSqa8EtRGmcQ78V7GlgVmIIlvgM4aji7P3d0nj3jV3OEgDibBHRsOZe sUsg== X-Gm-Message-State: AOJu0Yy6hzXlSc45zbaNA2GCkNzhZ/ydE6duLECmS7JbTDo0/yv1yn3h jHr/qHe4jFzocfxR5MQtIzV+sQ== X-Received: by 2002:a5d:6a43:0:b0:317:f7b0:85f with SMTP id t3-20020a5d6a43000000b00317f7b0085fmr7166588wrw.33.1692719412194; Tue, 22 Aug 2023 08:50:12 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id q8-20020a5d5748000000b003196e992567sm16091082wrw.115.2023.08.22.08.50.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Aug 2023 08:50:11 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 69FB61FFBB; Tue, 22 Aug 2023 16:50:11 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , =?utf-8?q?Daniel_?= =?utf-8?q?P=2E_Berrang=C3=A9?= , Thomas Huth , Markus Armbruster , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Juan Quintela Subject: [RFC PATCH] docs/style: permit inline loop variables Date: Tue, 22 Aug 2023 16:50:04 +0100 Message-Id: <20230822155004.1158931-1-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42d; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x42d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org I've already wasted enough of my time debugging aliased variables in deeply nested loops. While not scattering variable declarations around is a good aim I think we can make an exception for stuff used inside a loop. Signed-off-by: Alex Bennée Reviewed-by: Stefan Hajnoczi Reviewed-by: Richard Henderson Reviewed-by: Thomas Huth Reviewed-by: Philippe Mathieu-Daudé Acked-by: Markus Armbruster --- docs/devel/style.rst | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/devel/style.rst b/docs/devel/style.rst index 3cfcdeb9cd..2f68b50079 100644 --- a/docs/devel/style.rst +++ b/docs/devel/style.rst @@ -204,7 +204,14 @@ Declarations Mixed declarations (interleaving statements and declarations within blocks) are generally not allowed; declarations should be at the beginning -of blocks. +of blocks. To avoid accidental re-use it is permissible to declare +loop variables inside for loops: + +.. code-block:: c + + for (int i = 0; i < ARRAY_SIZE(thing); i++) { + /* do something loopy */ + } Every now and then, an exception is made for declarations inside a #ifdef or #ifndef block: if the code looks nicer, such declarations can