CODING_STYLE: Section about mixed declarations
diff mbox

Message ID 1391936581-8382-1-git-send-email-ehabkost@redhat.com
State New
Headers show

Commit Message

Eduardo Habkost Feb. 9, 2014, 9:03 a.m. UTC
We had an unwritten rule about declarations having to be at beginning of
blocks. Make it a written rule.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 CODING_STYLE | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Fam Zheng Feb. 10, 2014, 1:33 a.m. UTC | #1
On Sun, 02/09 07:03, Eduardo Habkost wrote:
> We had an unwritten rule about declarations having to be at beginning of
> blocks. Make it a written rule.
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>  CODING_STYLE | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/CODING_STYLE b/CODING_STYLE
> index dcbce28..f6eb319 100644
> --- a/CODING_STYLE
> +++ b/CODING_STYLE
> @@ -84,3 +84,10 @@ and clarity it comes on a line by itself:
>  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.
> +
> +5. Declarations
> +
> +Mixed declarations (interleaving statements and declarations within blocks) are
> +not allowed; declarations should be at beginning of blocks.  In other words,
> +the code should not generate warnings if using GCC's
> +-Wdeclaration-after-statement option.

What is the reason that we don't use -Wdeclaration-after-statement in Makefile?
Thanks.

Fam
Eduardo Habkost Feb. 10, 2014, 8:16 a.m. UTC | #2
On Mon, Feb 10, 2014 at 09:33:06AM +0800, Fam Zheng wrote:
> On Sun, 02/09 07:03, Eduardo Habkost wrote:
> > We had an unwritten rule about declarations having to be at beginning of
> > blocks. Make it a written rule.
> > 
> > Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> > ---
> >  CODING_STYLE | 7 +++++++
> >  1 file changed, 7 insertions(+)
> > 
> > diff --git a/CODING_STYLE b/CODING_STYLE
> > index dcbce28..f6eb319 100644
> > --- a/CODING_STYLE
> > +++ b/CODING_STYLE
> > @@ -84,3 +84,10 @@ and clarity it comes on a line by itself:
> >  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.
> > +
> > +5. Declarations
> > +
> > +Mixed declarations (interleaving statements and declarations within blocks) are
> > +not allowed; declarations should be at beginning of blocks.  In other words,
> > +the code should not generate warnings if using GCC's
> > +-Wdeclaration-after-statement option.
> 
> What is the reason that we don't use -Wdeclaration-after-statement in Makefile?
> Thanks.

We have around 39 files today that don't follow the rule, today, and
would generate warnings if we used -Wdeclaration-after-statement.
Stefan Hajnoczi Feb. 14, 2014, 2:38 p.m. UTC | #3
On Sun, Feb 09, 2014 at 07:03:01AM -0200, Eduardo Habkost wrote:
> We had an unwritten rule about declarations having to be at beginning of
> blocks. Make it a written rule.
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>  CODING_STYLE | 7 +++++++
>  1 file changed, 7 insertions(+)

I think C99 mixed declarations and code are a good thing.  It's easier
to read code when the local variable type is alongside the
initialization.

I'll try to avoid mixed declarations and code if the others feel this
rule is worthwhile.

Stefan
Eduardo Habkost Feb. 19, 2014, 7:34 p.m. UTC | #4
Ping? Who is willing to apply this?

On Sun, Feb 09, 2014 at 07:03:01AM -0200, Eduardo Habkost wrote:
> We had an unwritten rule about declarations having to be at beginning of
> blocks. Make it a written rule.
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>  CODING_STYLE | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/CODING_STYLE b/CODING_STYLE
> index dcbce28..f6eb319 100644
> --- a/CODING_STYLE
> +++ b/CODING_STYLE
> @@ -84,3 +84,10 @@ and clarity it comes on a line by itself:
>  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.
> +
> +5. Declarations
> +
> +Mixed declarations (interleaving statements and declarations within blocks) are
> +not allowed; declarations should be at beginning of blocks.  In other words,
> +the code should not generate warnings if using GCC's
> +-Wdeclaration-after-statement option.
> -- 
> 1.8.5.3
> 
>

Patch
diff mbox

diff --git a/CODING_STYLE b/CODING_STYLE
index dcbce28..f6eb319 100644
--- a/CODING_STYLE
+++ b/CODING_STYLE
@@ -84,3 +84,10 @@  and clarity it comes on a line by itself:
 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.
+
+5. Declarations
+
+Mixed declarations (interleaving statements and declarations within blocks) are
+not allowed; declarations should be at beginning of blocks.  In other words,
+the code should not generate warnings if using GCC's
+-Wdeclaration-after-statement option.