qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH] docs/style: permit inline loop variables
@ 2023-08-22 15:50 Alex Bennée
  2023-08-22 15:52 ` Stefan Hajnoczi
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Alex Bennée @ 2023-08-22 15:50 UTC (permalink / raw)
  To: qemu-devel
  Cc: Alex Bennée, Daniel P. Berrangé, Thomas Huth,
	Markus Armbruster, Philippe Mathieu-Daudé, Juan Quintela

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 <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
-- 
2.39.2



^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-08-31 13:29 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-22 15:50 [RFC PATCH] docs/style: permit inline loop variables Alex Bennée
2023-08-22 15:52 ` Stefan Hajnoczi
2023-08-22 15:57 ` Peter Maydell
2023-08-23  5:59   ` Markus Armbruster
2023-08-24 13:18     ` Peter Maydell
2023-08-31 13:29       ` Markus Armbruster
2023-08-22 16:09 ` Richard Henderson
2023-08-22 16:13 ` Thomas Huth
2023-08-22 16:31 ` Philippe Mathieu-Daudé

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).