Free Static Code Analysis with Eclipse
Join the DZone community and get the full member experience.Join For Free
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.
Published at DZone with permission of Erich Styger, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.