[gst-devel] more warning flags

Benjamin Otte otte at redhat.com
Thu Mar 11 15:37:33 CET 2010


Hey everybody - and in particular OS X and Windows hackers,

I'm currently in the process of adding more gcc warning flags to the
GStreamer build. The plumbing in the common/ submodule should be
complete for that and the has all the flags already.
What is missing now is converting the plugins, and I'm doing that step
by step.

However, I cannot run all compiler versions and compile all the plugins,
so I might not catch all the warnings. So if you encounter some, either
just fix them - my commit for a particular flag might give hints on how
to do that - or poke me on IRC or via email. Keeping the code building
is definitely my highest priority.


You can read about all the warning options in the gcc documentation[1]
or in an old blog post of mine[2].
Most of them cause very little issues, but some of them are a little
more likely to cause failures, so I'll talk about them explicitly here:

1) -Wmissing-declarations -Wmissing-prototypes -Wredundant-decls
These 3 warnings together ensure that every non-static function is
dclared exactly once before its first use - no matter if you use or
implement that function. So it requires fixing the headers to contain
all non-static functions and actually including those headers.

2) -Wwrite-strings
This makes gcc treat every string literal as a const string. This is
useful because string literals are in fact const strings and so must not
be modified. It often causes headaches because functions - both in
internal and external APIs - take "char *" arguments when they meant to
say "const char *". In the internal APIs we can fix that, (making stuff
const is not an API or ABI break usually), but in the external APIs we
have to do the cast.

3) -Wcast-align
I'd like to enable this warning as it's useful for embedded, but because
I can't test it and because I'm not sure how many warnings it'll cause,
I won't enable it for the plugins. I assume there to be quite a few
cases where GST_BUFFER_DATA() casts have to be audited.
This warning only triggers for targets that have alignment requirements
- like ARM. It triggers when you're trying to cast to a type with
stricter alignment requirements than the type you're casting from. If
you know the cast is safe, you can do an intermediate cast to gpointer
to shut the warning up. So to give an example, this code:
  guint16 *samples = (guint16 *) GST_BUFFER_DATA (buffer);
would cause such a warning. As we know that buffer data is always 16bit
aligned when doing 16bit audio, we can rewrite this to say
  guint16 *samples = (guint16 *) (gpointer) GST_BUFFER_DATA (buffer);
or even
  guint16 *samples = (gpointer) GST_BUFFER_DATA (buffer);
Both of those won't throw the warning. 
This warning makes life a whole lot easier for embedded people, so if
one of you were to look into enabling that flag, that'd be great.

Cheers,
Benjamin


[1]: http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
[2]: http://blogs.gnome.org/otte/2008/12/22/warning-options/





More information about the gstreamer-devel mailing list