From patchwork Thu Aug 24 16:39:02 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: 1825517 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=vA04Pnyi; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RWplB0vyPz1ygJ for ; Fri, 25 Aug 2023 02:41:58 +1000 (AEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qZDMn-0006Mx-3Y; Thu, 24 Aug 2023 12:39:29 -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 1qZDMk-0006Ln-W5 for qemu-devel@nongnu.org; Thu, 24 Aug 2023 12:39:27 -0400 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qZDMb-00087H-92 for qemu-devel@nongnu.org; Thu, 24 Aug 2023 12:39:26 -0400 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-3fea0640d7aso233125e9.0 for ; Thu, 24 Aug 2023 09:39:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692895155; x=1693499955; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=iiC7cvPGqtDwu4nVf8eS+Cmc1lWchz2oWST+0j9UI/U=; b=vA04Pnyi1MC8iOQivkJG13qqRHXhRXuNG7cUOMxumPJZedRGejr4eELLl0BrlJyUqV Vd3n/9aUMUboZS3CWZ9lfs67ilKCYueY1h+GPvUoAEg2hwJIF2ezCfTY23rQxpdGn96n AUkUD3bu5RDU2QLQB46APSKzlD6/v4AGjV3U/9/xpLDi//2nBJ+92F1576o2Y+MUr4zX /6Ewj6uwLFC0TRSeEYj0Ri1Xoka63RPdCCYj7cUt5Fh3cixZiZSR2xn+WXOCawLN2wKt tBjFnXRyU6bIG0ix4WNxK119p1EeUcp5omVUWMmQnuj4rH5ZhCFvMmXYcLpLmMeb2Pvn OB8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692895155; x=1693499955; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iiC7cvPGqtDwu4nVf8eS+Cmc1lWchz2oWST+0j9UI/U=; b=kS6yqw+/bU8mTCR13TsnsnP71NpImMLG5PJqtj1gKAhPc+QkWJHVOo5e6rksxwnYZV 4k49mSvfzirUQmoGrK2Pe7iuJU6gwQW275/7y1U3yg+ijRv1x/QcPVRyRVWqfYY+whXL KKPaxUd74K2drAuFTZa/F+dtf1FJ5zup2HaplllbHvleCp+HBwurFrqzOcl1zKIXnUJP J4DN60Wq1HdPrIsEwEUOEUOZWvad0KPjX88IWkBlq5Wxq35ABrcggzu7uMmlA8B6ld89 C81PObxGe2/5SGCpB8nMCFcUkN95d14oDoAdPnQdMwbzW5sXOyDKLKNaPSPy8GCwgnSw A+7g== X-Gm-Message-State: AOJu0Yx0lHB2Z41VEiBShOcuyhjSMfz5SsDf4LPZtEXUzcN03YmCl2Y7 0bSEVUf90LMND89yRfl7+ro0YQ== X-Google-Smtp-Source: AGHT+IHSweN2nQXLY2hUsg1P0sRg0uZ2PyL46Pd2IcPdyY94+9MW/izk/pyT8hI4pKtfh/hYV+9+Vw== X-Received: by 2002:a05:600c:28c:b0:401:b0f2:88cc with SMTP id 12-20020a05600c028c00b00401b0f288ccmr1218595wmk.41.1692895155495; Thu, 24 Aug 2023 09:39:15 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id s16-20020a05600c045000b003fee0741b8csm3070971wmb.23.2023.08.24.09.39.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Aug 2023 09:39:13 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id A942F1FFBF; Thu, 24 Aug 2023 17:39:10 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: Beraldo Leal , Nicholas Piggin , Richard Henderson , Markus Armbruster , Yonggang Luo , qemu-ppc@nongnu.org, David Gibson , Daniel Henrique Barboza , qemu-s390x@nongnu.org, Akihiko Odaki , =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-arm@nongnu.org, Juan Quintela , Thomas Huth , Peter Maydell , Ilya Leoshkevich , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , David Hildenbrand , Greg Kurz , Wainer dos Santos Moschetta , =?utf-8?q?Philippe_Mathi?= =?utf-8?q?eu-Daud=C3=A9?= , =?utf-8?q?C=C3=A9dric_Le_Goa?= =?utf-8?q?ter?= , Stefan Hajnoczi Subject: [PATCH v2 04/12] docs/style: permit inline loop variables Date: Thu, 24 Aug 2023 17:39:02 +0100 Message-Id: <20230824163910.1737079-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230824163910.1737079-1-alex.bennee@linaro.org> References: <20230824163910.1737079-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::331; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x331.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=unavailable 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.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. Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Stefan Hajnoczi Acked-by: Markus Armbruster Reviewed-by: Thomas Huth Reviewed-by: Richard Henderson Signed-off-by: Alex Bennée Message-Id: <20230822155004.1158931-1-alex.bennee@linaro.org> --- 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