[MPlayer-dev-eng] [PATCH] More warnings

Uoti Urpala uoti.urpala at pp1.inet.fi
Sun Feb 6 23:22:45 CET 2011


On Sun, 2011-02-06 at 22:17 +0100, Reimar Döffinger wrote:
> On Sun, Feb 06, 2011 at 09:50:07PM +0100, Ingo Brückl wrote:
> > Concerning -Wcast-qual and -Wwrite-strings: When using these you have to very
> > carefullly distinguish between char * and const char * which could mean a lot
> > of fixes because this usually isn't done in C programs. Could be a nuisance
> > when you need to call old char * functions with new const char * variables,
> 
> Both of these almost always indicate really bad design or an error.

This is not true. I'd say the opposite is often the case - tinkering
with const qualifiers in C indicates that the author inappropriately
focused on practically meaningless details and missed what's important.

> The few cases where they don't are easy enough to ignore.

This is not true either. One large and general class of counterexamples
is code that passes values forward without itself modifying them (strchr
in the standard C library is a canonical example). If such code uses
"const" that will require casting away the qualifier to modify the value
in later code; if such code does not use "const" then any calling code
that insists on using "const" will need to cast away the qualifier. Such
cases are not particularly rare, and insisting on using "const" _and_
-Wcast-qual to prevent silencing the resulting warnings is especially
bad practice.

Note that the C standard committee recognized the problems, and
intentionally made string literals "char *" rather than "const char *",
even though they're not writable. While "const" qualifiers do have some
valid uses, in most cases trying to keep non-writable objects in const
pointers only is more trouble than it's worth.



More information about the MPlayer-dev-eng mailing list