qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] docs/style: allow C99 mixed declarations
@ 2024-02-05 17:18 Stefan Hajnoczi
  2024-02-05 17:41 ` Daniel P. Berrangé
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Stefan Hajnoczi @ 2024-02-05 17:18 UTC (permalink / raw)
  To: qemu-devel
  Cc: Hanna Czenczek, Markus Armbruster, Philippe Mathieu-Daudé,
	Daniel P. Berrangé, Peter Maydell, Richard Henderson,
	Thomas Huth, Alex Bennée, Stefan Hajnoczi

C99 mixed declarations support interleaving of local variable
declarations and code.

The coding style "generally" forbids C99 mixed declarations with some
exceptions to the rule. This rule is not checked by checkpatch.pl and
naturally there are violations in the source tree.

While contemplating adding another exception, I came to the conclusion
that the best location for declarations depends on context. Let the
programmer declare variables where it is best for legibility. Don't try
to define all possible scenarios/exceptions.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 docs/devel/style.rst | 20 --------------------
 1 file changed, 20 deletions(-)

diff --git a/docs/devel/style.rst b/docs/devel/style.rst
index 2f68b50079..80c4e4df52 100644
--- a/docs/devel/style.rst
+++ b/docs/devel/style.rst
@@ -199,26 +199,6 @@ Rationale: a consistent (except for functions...) bracing style reduces
 ambiguity and avoids needless churn when lines are added or removed.
 Furthermore, it is the QEMU coding style.
 
-Declarations
-============
-
-Mixed declarations (interleaving statements and declarations within
-blocks) are generally not allowed; declarations should be at the beginning
-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
-be placed at the top of the block even if there are statements above.
-On the other hand, however, it's often best to move that #ifdef/#ifndef
-block to a separate function altogether.
-
 Conditional statements
 ======================
 
-- 
2.43.0



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

end of thread, other threads:[~2024-02-07  7:38 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-05 17:18 [PATCH] docs/style: allow C99 mixed declarations Stefan Hajnoczi
2024-02-05 17:41 ` Daniel P. Berrangé
2024-02-05 17:55   ` Peter Maydell
2024-02-05 18:12   ` Samuel Tardieu
2024-02-05 19:06     ` Stefan Hajnoczi
2024-02-05 19:17       ` Daniel P. Berrangé
2024-02-06  5:53   ` Markus Armbruster
2024-02-07  5:28     ` Philippe Mathieu-Daudé
2024-02-07  7:37       ` Markus Armbruster
2024-02-05 23:17 ` Alex Bennée
2024-02-06 13:48 ` Stefan Hajnoczi

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).