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: 1827830 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=XZIceiIl; 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 4RbS501hFFz1yZs for ; Thu, 31 Aug 2023 00:55:00 +1000 (AEST) 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-Google-Smtp-Source: AGHT+IHvF+2t6OFOepDX9rpS7oQ2MF91c+8dK7+lsR86r8JRVqLH6dOifjec6w/hh7YxjTvd3f5abQ== 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+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: <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