g++ verifies predetermined set of rules and constraints which if not met in code throws an error or warning messages. Is it possible using some tool to create a parser for custom set of rules such as "global variables need to be explicitly initialized" (I know global variables are implicitly initialized), or functions with name init has been called (I know about constructors but don't want to use them). Any pointers to something quick and simple would be useful.
Asked
Active
Viewed 1,205 times
1
-
possible duplicate of [C/C++ Free alternative to Lint?](http://stackoverflow.com/questions/632057/c-c-free-alternative-to-lint) – Martin York Aug 20 '12 at 05:32
-
1* – * then you are **not using C++**. You just want C; for that `lint` is a very good static analyses.Martin York Aug 20 '12 at 05:34
-
@LokiAstari cppcheck and lint looks like a good tool. I will check those out. – Kabira K Aug 20 '12 at 18:26
2 Answers
2
Coverity lets you write custom rules like this. It's kind of expensive, so probably not a hobby kind of thing to set up just for this. It's a good tool for production code, though, and extensible.

Michael
- 617
- 4
- 3
0
CLANG is a static code analyser used to insure that you wrote what you meant, even if what you wrote would compile anyway. It does sttic code analysis only.
Otherwise use assert() or exceptions to enfore rules at runtime.

awiebe
- 3,758
- 4
- 22
- 33
-
1Clang is not a static code analyzer, it is set of libraries for parsing, compiling and analyzing programs written in the C language family (C, C++, Objective-C, Objective-C++). The clang project *includes* a static analyzer, but it cannot be reduced to it. Still, you are right that using the Clang libraries is probably the OP's best bet. – Matthieu M. Aug 20 '12 at 08:45