Tuning out PC-lint issues in libraries

Regardless of which libraries you use in your projects, you are likely to encounter PC-lint issues in class or macro definitions within those libraries. When you do not have any control over the implementation of the libraries concerned, such "noise" can be irritating to say the least (athough it could of course be indicative of a real problem with the library implementation which you should probably be aware of).

Fortunately, using some of PC-lint's error suppression directives it is in most cases relatively easy to write lint directives to prevent this happening, for example:

-emacro(1924, MAKE_HRESULT)
-esym(1932, ATL::CAtlExeModuleT<*>)
-etype(1746, boost::shared_ptr<*>)

The directives -emacro, -esym and -etype suppress issues in macros, named symbols, and instances of objects or values of the given type respectively (note the availability of wildcards here).

PC-lint has quite a number of such options for fine-grained control of warning policy, and it is well worth getting to know how to use them effectively. You can also use them in the code directly by prefixing them with a //lint comment, for example:

//lint -esym(1712, CoreLib::CSomeClass)

A special mention should be reserved for the "sledgehammer of last resort" for noisy library header files, which looks something like this:

//lint -save -e686 -w0
#include "NoisyHeader.h"
//lint -restore

The meaning of the above should be fairly self-explanatory - the header in question has so much wrong with it (or maybe it is a third party library) that we are just going to disable any issues from it for now by setting the warning level to 0 (the -e686 prevents a warning about you doing so).

Of course, if you find yourself doing this as anything but a short term measure you should probably be asking whether the header in question has a long term place in your codebase.

If you are setting up Visual Lint for use with PC-lint for the first time, you might find it useful to take a look at the PC-lint configuration files we use ourselves.

On the Visual Lint downloads page you will find a zipfile containing std.lnt files for several supported IDEs, as well as the options.lnt file which defines our warning policy and the rb-win32-pclint8.lnt and rb-win32-pclint9.lnt files we use to suppress common issues in the Win32 API and the MFC, ATL and WTL frameworks (the latter are also installed with Visual Lint - see PC-lint indirect files).

Should you need to write your own detailed suppression files, an examination of these files should help you to write your own.



Copyright © 2004 - 2015 by Riverblade Ltd. All rights reserved.