Blog


Improving Project Accuracy (C/C++)

Usually just identifying the root of your source tree and saying "Analyze" will provide you with a accurate, useful Understand project. Sometimes, however, you need a more accurate representation of your project. Maybe you have large swaths of inactive code that should be enabled, maybe there are grayed out (unresolved) entities that do exist in the source code, or maybe the metrics don’t seem to line up. In cases like this, you will want to use some of the advanced C++ options to fine tune the parse. Here are some things that will improve the parse accuracy.


Set the Compilerimage

Under Project->Configure Project -> C++ Options there is a section that allows you to set your compiler and the location of your Compilers include files. Setting these two options to the correct settings will provide the default pragmas and macros as well as include files that your project needs. In many cases just performing this one step will be all you need to do to get the accuracy you are after.

Set Include Paths

Your project probably depends on header files from other places, both system header files, like time.h, and those to your own team’s libraries.  The easiest way to identify these header files is to expand the parse log while Understand is parsing, and hit the "Include Paths" button. This will open the Parse Improvement Tool that lets you search for and quickly find missing include paths. These include paths can also be specified in Project->Configure Project -> C++ -> Includes.

Found include files are not added to the project unless you specify the option to do so. Instead Understand will parse those files and record the Macro definitions, types, include paths, and other data that pertains to your projects source files. So when you view information on a class that is used in your project, but defined elsewhere, Understand can now answer questions about it.image

Set Macros

While in the parse log, you can also add definitions for undefined macros which will completely change how the code is analyzed. You can define macros at the project level, folder level, or just for a particular file. The new tool for specifying macros makes it very easy to identify how often and where a macro is used. That will let you know which ones are most critical to define for an accurate parse. The macros can also be defined in the Project->Configure Project -> C++ -> Macros page.

image2[1]

Set File Types

If you have non standard file extensions, you will want to set them under Project->Configure Project->File Types screen. That will ensure that they get parsed correctly. Also, if your project is pure C, you may want to change the appropriate extensions to parse with C instead of C++. This can lead to a more accurate parse for C files.

Disable the Include Cache

Project->Configure Project->C++ Options has an option to "Use the Include Cache". This significantly speeds up parsing by caching the values of a file the first time it is looked at. In reality though, every time a file is parse by the compiler its contents can change dynamically based off the context it was included in. Disabling the include cache by unchecking the box will make the parse time slower, but will lead to a more accurate parse.

Tags: ,


2 Responses to “Improving Project Accuracy (C/C++)”

  1. SciTools Blog » Blog Archive » C++ Template and Overload Support (Beta) Says:

    [...] Our current C++ parser was written with the goal of being able to use fuzzy logic to handle incomplete, non-compiling code gracefully and as accurately as possible. It does a great job at that and will continue to be an important part of our toolset. Unfortunately that same feature caused severe difficulties in parsing templates and recognizing overloaded functions.  The new parser is more strict than the old parser and requires a more accurate project definition. If you plan on using it, please follow the instructions from this post to ensure your project is as correct as possible:  Improving Project Accuracy (C/C++) [...]

  2. SciTools Blog » Blog Archive » Objective C Support Says:

    [...] on it.  This support is added as part of the new strict analyzer, so make sure your project is fully configured to get an accurate parse. Please point Understand and your Objective-C code, and if you run into [...]