Wish: Variable Not Used Warning
Don
nospam at nospam.com.au
Thu Jul 10 03:20:21 PDT 2008
Bruce Adams wrote:
> On Wed, 09 Jul 2008 09:49:34 +0100, Walter Bright
> <newshound1 at digitalmars.com> wrote:
>
>> Here are some horrid examples from my own code which, to please the
>> client, had to compile with all warnings on for MSVC:
>>
>> ---
>> p = NULL; // suppress spurious warning
>> ---
>> b = NULL; // Needed for the b->Put() below to shutup a compiler
>> use-without-init warning
>> ---
>> #if _MSC_VER
>> // Disable useless warnings about unreferenced formal parameters
>> #pragma warning (disable : 4100)
>> #endif
>> ---
>> #define LOG 0 // 0: disable logging, 1: enable it
>>
>> #ifdef _MSC_VER
>> #pragma warning(disable: 4127) // Caused by if (LOG)
>> #endif // _MSC_VER
>> ---
>>
>> Note the uglification this makes for code by forcing useless
>> statements to be added. If I hadn't put in the comments (and comments
>> are often omitted) these things would be a mystery.
>
> I would contend this is a problem with the quality of headers provided
> by M$.
> Library code has a greater need to be high quality than regular code.
> Operating system APIs even more so.
> Removing warnings from C/C++ headers requires you to write them
> carefully to
> remove the ambiguity that leads to the warning. That is, this definition of
> quality is a measure that increases with decreasing semantic ambiguity.
I think it's a complete fallacy to think that lower-number-of-warnings
is proportional to better-code-quality.
Once a warning is so spurious (eg, so that it has a <1% chance of being
an error), it's more likely that you'll introduce an error in getting
rid of the warning.
In C++, error-free code is clearly defined in the spec. But warning-free
code is not in the spec. You're at the mercy of any compiler writer who
decides to put in some poorly thought out, idiotic warning.
If you insist on avoiding all warnings, you're effectively using the
programming language spec which one individual has carelessly made on a
whim.
For example, VC6 generates some utterly ridiculous warnings. In some
cases, the chance of it being a bug is not small, it is ZERO.
In DMD, the signed/unsigned mismatch warning is almost always spurious.
Getting rid of it reduces code quality.
More information about the Digitalmars-d
mailing list