Wish: Variable Not Used Warning

Bruce Adams tortoise_74 at yeah.who.co.uk
Wed Jul 9 17:16:55 PDT 2008


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.
Asking users of your library code to disable warnings with a #pragma is  
laziness
that a big monopoly like M$ can get away with. Then people wrongly start  
to think
its okay because the big monopoly does it.

Regards,

Bruce.



More information about the Digitalmars-d mailing list