[rtmpdump] patch: gcc -Wextra

Peter Miller pmiller at opensource.org.au
Sat Apr 9 02:21:22 CEST 2011

On Fri, 2011-04-08 at 11:34 -0700, Howard Chu wrote:
> Peter Miller wrote:
> > This patch adds the gcc -Wextra flag, and fixes all the warnings it
> > produces.
> Rejecting this patch. The C standard specifies that structure elements after 
> the last explicitly initialized one are all zero-filled. Explicit 
> initialization is not required.

Like many of gcc warnings, the virtue of -Wmissing-field-initializers
(implied by -Wextra) is not immediately obvious.  The merit comes when
you add another field to a struct, and the initializers (elsewhere in
the code) become out-of-date, and non-obviously wrong (to the compiler
at least).  With this warning enabled, the compiler will produce a
warning for each point in the code where it is used, allowing inspection
and correction if necessary.

Unions are more difficult, because many compilers don't like
initializers for them; and if they do permit them, the convention of
initializing the first union member is not universal.  This is why I
used the "static struct foo foo_zero; struct foo var = foo_zero;" idiom,
because it ensures the union is initialized.  Another advantage of the
static zero idiom is that *all* of the stucture is initialized,
including any "gaps" between members -- this is important when using
valgrind(1) to look for accesses to uninitialized memory, and other
memory issues valgrind(1) is good for.

So, yes, at first sight, this patch could look unnecessary, but in my
experience, gcc warnings are very useful for finding problems before
they happen.  No-one goes to the effort of writing gcc code for no
reason, and all gcc warnings are there because they consistently find
bugs.  All the false positives are worth it when gcc finds a bug for
you, and this is why I use -Werror to turn warnings into errors.

Peter Miller <pmiller at opensource.org.au>
/\/\*        http://miller.emu.id.au/pmiller/

PGP public key ID: 1024D/D0EDB64D
fingerprint = AD0A C5DF C426 4F03 5D53  2BDB 18D8 A4E2 D0ED B64D
See http://www.keyserver.net or any PGP keyserver for public key.

"Spontaneous combustion doesn't just happen."

More information about the rtmpdump mailing list