From patchwork Wed Aug 30 14:53:59 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: 718580 Delivered-To: patch@linaro.org Received: by 2002:adf:d20a:0:b0:31d:da82:a3b4 with SMTP id j10csp585110wrh; Wed, 30 Aug 2023 07:54:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE8eu8LIk0ndmXXMwoECQoB8/2fWhGCMFLUmxOerynT8w22wxIZLml2wp/4bSDtRvSWXX+M X-Received: by 2002:a05:6214:2b85:b0:63d:3eb5:4d80 with SMTP id kr5-20020a0562142b8500b0063d3eb54d80mr2165959qvb.42.1693407298833; Wed, 30 Aug 2023 07:54:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693407298; cv=none; d=google.com; s=arc-20160816; b=duvJQGxAMeJsJpyjx0nugQsCPze6dn/2TsGSnsIr7G1bnEHd90HHifISMC1A7k89uu cFnTFoOMhC70NuokwPBxAZKmlRh6gIiGNsJcTw4SMjS8w4C8nmh34urpmSrSJiHO7YM6 rd7SA52TvIaaVWvJrYBtMyiZMP3mrtfBTM86c7edXCEjzISa9Tk/hthGOmDiy5rOWBJB ZUjulOb4iWnbjfAZSwp1K8TQNZ8m/ckn1e8DPgNLaTWwXIOAkYfUCH9VqxODGZWdI1nK jtCJrODvhwanrT5t2ldrVjd/CHuZ+hV57ZHsZSlOEaYrOoJuJSKRYYgHRge/azapfBpz m1ZQ== 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:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=uH3otyEIeLq3dLGPNCMZELh485heJIDu3uWi+lqceck=; fh=4cQC2NIX/GHEzRvNd1Zau9/BfIoEE2kRGDXXAngn3G0=; b=j+6sj6CHtwnKCvu9cNgiA8O/w6I3hP5HFWdJo77Uic1jhRV433VFWcAbjRCUGdR3R+ focg1CWqXKTqaT8VMxE0x6OFDfkc6c6ui9XOXpGABB0NQDqHrFCmMeVvoeGNVzYUZ//Q Q/V1txyDa9fXI7vBSBHgbUSRDBZ9+DsHtWr0GE0MBHdKBIN5YDlGJf+0PakaCtPu2xXV zVYjvZ/nx1VD2YCKq26ViuqGr1kkk8nFdqdNniKraR5UyF6wqA+jRaxwRtffhJke3zeX Y3LzDmOdl7a/wc7Sd3/9vJPUB4vQja4Hwzs2Phw7kLuvbfM6tcP4TwRSQle8Rg0uYPrQ Wnng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XZIceiIl; 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 qs13-20020a05620a394d00b0076f2c73cff6si791348qkn.697.2023.08.30.07.54.58 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 30 Aug 2023 07:54:58 -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=XZIceiIl; 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 1qbMaG-0001AY-NV; Wed, 30 Aug 2023 10:54:16 -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 1qbMaF-00019t-HS for qemu-devel@nongnu.org; Wed, 30 Aug 2023 10:54:15 -0400 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qbMaB-0000ji-M9 for qemu-devel@nongnu.org; Wed, 30 Aug 2023 10:54:15 -0400 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-401b3ea0656so51730515e9.0 for ; Wed, 30 Aug 2023 07:54:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1693407250; x=1694012050; darn=nongnu.org; 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=uH3otyEIeLq3dLGPNCMZELh485heJIDu3uWi+lqceck=; b=XZIceiIliKeKjndId2v9ttLbfJlYZOmm9rGJTGUlVYHgpDvalnBTk1PN+Y1Y+0ayov JZAtYTAXadOpFB0Z4Lh7gXA5oNtcDOcWzh5zR1MmgTxXzNoyGq7m/rukCechDJIGtZwa QWGCH1QZ3Diva4PRJuE6ghHOTiAGsUYLCIsBTJQVGcwa8OgO2UB8S6ONzqG0tjPX8dsV jm+mNPCEjupQuCg9n/G9ZQ1zjMLoXYtVEfk60ov/8VddAU2oaIlmhcoYMFP3/CpgaPR9 +6vsSJTmjVJVcute7KPsZ3Ns3H415sICn7qIxtuIGwBMDcQAb8ajSR74eZ/8LIU6bPjP lzeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693407250; x=1694012050; 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=uH3otyEIeLq3dLGPNCMZELh485heJIDu3uWi+lqceck=; b=jefdpDMLt7zRnCvdGeAeWPM8E3oobl2hUiFwORm0w0sqDmawRqX8K4Vh+MI5EDq3dZ A8Uj1pkgrOyyEBRFIV9LHhnOU7d99/JwC6uTOMvtQdIuyGfoqyAl6ijQJUAXk6AM0hjW WpMlfD6BdNzMf43GI0pED5JX/L/qiuT5TC1gdEHo6qkOKofUZrCxrvl15g+l9M+z2Aln QIxsxGN8bS3BpVsgjhZev0kMtWTn6PYtajxeybTpbABnOIubeNJu4VndDxAQzDlGpFpy T5ohz3Kk+CvwhZzJ8Je4W5R6Y0dVFBvzCIydW6jszNrKNZAt7rRCaXT09uTDsym3hzzC QpCA== X-Gm-Message-State: AOJu0YzlvaqPYMnn/KgMrgNf2BeblnuBARZ21+uB/4nCzBu1ZsPxcyZQ 88BaUPsjQypoYq7DBF+cIJ17Fg== X-Received: by 2002:adf:cd0b:0:b0:317:f18b:a950 with SMTP id w11-20020adfcd0b000000b00317f18ba950mr1751701wrm.26.1693407250072; Wed, 30 Aug 2023 07:54:10 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id b4-20020adff244000000b0031423a8f4f7sm16871369wrp.56.2023.08.30.07.54.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Aug 2023 07:54:09 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 0E6D31FFBF; Wed, 30 Aug 2023 15:54:08 +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?Philipp?= =?utf-8?q?e_Mathieu-Daud=C3=A9?= , Stefan Hajnoczi , Markus Armbruster , Thomas Huth , Richard Henderson , =?utf-8?q?Daniel_P=2E_Ber?= =?utf-8?q?rang=C3=A9?= , Juan Quintela Subject: [PULL 04/12] docs/style: permit inline loop variables Date: Wed, 30 Aug 2023 15:53:59 +0100 Message-Id: <20230830145407.3064249-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230830145407.3064249-1-alex.bennee@linaro.org> References: <20230830145407.3064249-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::329; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x329.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. 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: <20230829161528.2707696-5-alex.bennee@linaro.org> 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