I know for myself: the earlier I’m able to fix a bug, the better. So I’m always grateful for things which help me to find issues in my sources as early in the development process as possible. Eclipse and CodeWarrior already help me to find syntax errors in my code while I’m typing:
With the built-in syntax checker of Eclipse, this helps me many times to get things right without the need to build my code with the compiler. But when I’m able to compile successfully my code, this does not mean it is without bugs. It would be good to catch as many errors *before* downloading and running it on the target.
I have presented a while ago PC-lint: but this does not come free of charge. The good news is that the new Eclipse version in CodeWarroir for MCU10.3 has static code analyser built-in: Code name “Codan”: not as powerful as PC-lint, but good enough as a little helper.
C/C++ Code Analysis
The static C/C++ Code Analysis is available if I select the project and use the context menu:
But when I run this, nothing seems to happen?
Enabling Code Analysis
The reason is that CodeWarrior has it disabled by default in a new workspace. It is enabled/disabled for each project. What I recommend is to enable it on the workspace level. Using the menu Window > Preferences and filter for ‘code’ shows the setting:
Usually I enable all the ‘Potential Programming Problems’:
The cool thing is: now it parses my sources in the background for problems:
Additionally it flags the problem place in the source view:
At any time, Code Analysis is run with the context menu on the project folder.
Customizing Code Analysis
The analysis is customized using the ‘Customize Selected..‘ Button:
I can configure the behaviour, such as if things are worth an error or are just a warning:
For example I can specify inclusion or exclusion pattern/files for each message:
:?: I have not found a way to configure/disable messages directly in the source files. That’s something I really like with PC-lint, but I’m not able to do with the Eclipse C/C++ Code Analysis?
I expect the features and functionality of the C/C++ Code Analysis to grow and extend over time in Eclipse. Right now it is able to catch not that many problems, and some are rather basic. But still: it helps to get my code right the first time. There are sometimes bogus messages, but then I can disable the messages or add that file to the ‘exclusion’ list. And even a small little helper adds to the benefits of Eclipse.
Happy analysing :)