qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] CODING_STYLE: Section about mixed declarations
@ 2014-02-09  9:03 Eduardo Habkost
  2014-02-10  1:33 ` Fam Zheng
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Eduardo Habkost @ 2014-02-09  9:03 UTC (permalink / raw)
  To: qemu-devel; +Cc: Paolo Bonzini, Andreas Färber, Peter Maydell

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

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

* Re: [Qemu-devel] [PATCH] CODING_STYLE: Section about mixed declarations
  2014-02-09  9:03 [Qemu-devel] [PATCH] CODING_STYLE: Section about mixed declarations Eduardo Habkost
@ 2014-02-10  1:33 ` Fam Zheng
  2014-02-10  6:09   ` Stefan Weil
  2014-02-10  8:16   ` Eduardo Habkost
  2014-02-14 14:38 ` Stefan Hajnoczi
  2014-02-19 19:34 ` Eduardo Habkost
  2 siblings, 2 replies; 6+ messages in thread
From: Fam Zheng @ 2014-02-10  1:33 UTC (permalink / raw)
  To: Eduardo Habkost
  Cc: Peter Maydell, Paolo Bonzini, qemu-devel, Andreas Färber

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

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

* Re: [Qemu-devel] [PATCH] CODING_STYLE: Section about mixed declarations
  2014-02-10  1:33 ` Fam Zheng
@ 2014-02-10  6:09   ` Stefan Weil
  2014-02-10  8:16   ` Eduardo Habkost
  1 sibling, 0 replies; 6+ messages in thread
From: Stefan Weil @ 2014-02-10  6:09 UTC (permalink / raw)
  To: Fam Zheng, Eduardo Habkost
  Cc: Peter Maydell, qemu-devel, Andreas Färber, Paolo Bonzini

Am 10.02.2014 02:33, schrieb Fam Zheng:
> 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,

at the beginning?

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

Maybe that would be a good idea. I did a short test and added that flag
in configure (where all gcc flags are checked before they are applied):

diff --git a/configure b/configure
index f7c672a..c10a1a8 100755
--- a/configure
+++ b/configure
@@ -331,6 +331,8 @@ ARFLAGS="${ARFLAGS-rv}"
 # default flags for all hosts
 QEMU_CFLAGS="-fno-strict-aliasing $QEMU_CFLAGS"
 QEMU_CFLAGS="-Wall -Wundef -Wwrite-strings -Wmissing-prototypes
$QEMU_CFLAGS"
+QEMU_CFLAGS="-Wdeclaration-after-statement $QEMU_CFLAGS"
+QEMU_CFLAGS="-Wno-error=declaration-after-statement $QEMU_CFLAGS"
 QEMU_CFLAGS="-Wstrict-prototypes -Wredundant-decls $QEMU_CFLAGS"
 QEMU_CFLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
$QEMU_CFLAGS"
 QEMU_INCLUDES="-I. -I\$(SRC_PATH) -I\$(SRC_PATH)/include"

The first result already shows 194 different violations. See
http://qemu.weilnetz.de/test/declaration-after-statement.txt for the
build protocol. As this test does not cover all source paths, there
might be even more violations. So the code will need some fixes before
this rule can be checked by -Wdeclaration-after-statement. Until this is
one, we could use -Wno-error=declaration-after-statement as I did in my
test.

The patch for CODING_STYLE is still useful.

Reviewed-by: Stefan Weil <sw@weilnetz.de>

Stefan

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

* Re: [Qemu-devel] [PATCH] CODING_STYLE: Section about mixed declarations
  2014-02-10  1:33 ` Fam Zheng
  2014-02-10  6:09   ` Stefan Weil
@ 2014-02-10  8:16   ` Eduardo Habkost
  1 sibling, 0 replies; 6+ messages in thread
From: Eduardo Habkost @ 2014-02-10  8:16 UTC (permalink / raw)
  To: Fam Zheng; +Cc: Peter Maydell, Paolo Bonzini, qemu-devel, Andreas Färber

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.

-- 
Eduardo

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

* Re: [Qemu-devel] [PATCH] CODING_STYLE: Section about mixed declarations
  2014-02-09  9:03 [Qemu-devel] [PATCH] CODING_STYLE: Section about mixed declarations Eduardo Habkost
  2014-02-10  1:33 ` Fam Zheng
@ 2014-02-14 14:38 ` Stefan Hajnoczi
  2014-02-19 19:34 ` Eduardo Habkost
  2 siblings, 0 replies; 6+ messages in thread
From: Stefan Hajnoczi @ 2014-02-14 14:38 UTC (permalink / raw)
  To: Eduardo Habkost
  Cc: Peter Maydell, Paolo Bonzini, qemu-devel, Andreas Färber

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

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

* Re: [Qemu-devel] [PATCH] CODING_STYLE: Section about mixed declarations
  2014-02-09  9:03 [Qemu-devel] [PATCH] CODING_STYLE: Section about mixed declarations Eduardo Habkost
  2014-02-10  1:33 ` Fam Zheng
  2014-02-14 14:38 ` Stefan Hajnoczi
@ 2014-02-19 19:34 ` Eduardo Habkost
  2 siblings, 0 replies; 6+ messages in thread
From: Eduardo Habkost @ 2014-02-19 19:34 UTC (permalink / raw)
  To: qemu-devel; +Cc: Paolo Bonzini, Andreas Färber, Peter Maydell

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

-- 
Eduardo

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

end of thread, other threads:[~2014-02-19 19:34 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-02-09  9:03 [Qemu-devel] [PATCH] CODING_STYLE: Section about mixed declarations Eduardo Habkost
2014-02-10  1:33 ` Fam Zheng
2014-02-10  6:09   ` Stefan Weil
2014-02-10  8:16   ` Eduardo Habkost
2014-02-14 14:38 ` Stefan Hajnoczi
2014-02-19 19:34 ` Eduardo Habkost

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