Override file

The __KLOCWORK__ macro supports generic code replacement using standard preprocessor mechanisms, and is very powerful, but it still means that you have to modify your source code specifically for Klocwork. If the modification you need to make to your code is localized to one or more macro definitions, you can use an override file and avoid source modification.

An override file is a header file that you import into your Klocwork project. The Klocwork compiler automatically includes and processes your override file with every source module built for the project. In the file, the Klocwork-specific preprocessor directive, #kw_override, is used to change the definition of macros in your source.

The #kw_override directive affects only macros, and only those macros that are defined in your production source.

For example, assume that in your production source you have this macro definition:

# define MY_ASSERT(x) (void) ((x) __handle_failed_assert(#x, __FILE__, __LINE__, __FUNCTION__))

If you want the compiler to see a simpler, more direct assertion, you can create an override file containing the following definition:

# kw_override MY_ASSERT(x) do { if( !(x) ) abort(); } while(0) 

To apply the override file to the integration build analysis, import it into a project or the projects_root directory. To apply the override file to your standalone desktop, use kwcheck import.