Metrics collection tools for C and C++ Source Code
This page lists various static code analysis tools that compute metrics
defined on C and C++ source code. The metrics are primarily size and
complexity of various types (lines of code, Halstead, McCabe, etc.).
You will need a C or C++ compiler to build most of these tools.
For tools that use shell or perl scripts, you will need the appropriate
interpreter to run them; these interpreters are on all unix systems.
The source files for each tool are available here. The files have
been packed into Unix-style tar files, which in turn have been
compressed with the GNU utility gzip.
PC users must have long file names (i.e., a win32 system) to unpack
them. Note that the GNU utilities are available for the PC, and
include both gunzip (uncompressing utility) and tar
(unpacking utility).
Collected Tools
Many of the tools are collected on (and available from) this web site.
The tools, in alphabetical order, are the following:
- c_lines
(gzip'ed tarfile)
Count lines, not counting comments, blank lines or form feeds.
Does a separate count of preprocessor directives.
Written by Dan Kozak around 1994.
Implemented in awk.
- cccc
(gzip'ed tarfile)
A metric analyser that provides a range of potentially
interesting measures for C, C++, Java, Ada-83, and Ada-95
code.
Written by Tim Littlefair of Edith Cowan University, Australia.
Implemented in C using PCCTS, a freely available set of
compiler-construction tools.
A far more recent version is available here:
http://cccc.sourceforge.net/
- c_count
(gzip'ed tarfile)
C_COUNT counts C-language source statements, and summarizes
statistics about the relative amount of commentary,
whitespace, etc.
Written by Thomas E. Dickey in 1991, last updated 1998.
Implemented in C.
- ccount
(gzip'ed tarfile)
Counts bytes, lines, language keywords, comment bytes, semicolons,
block length, nesting depth, and many more; about 77 metrics total.
Written by Joerg Lawrenz in 1993.
Implemented in C using yacc and lex.
- clc
(gzip'ed tarfile)
Counts total lines, noncomment lines, and statements in C/C++ source.
Written by Brad Appleton in 1995. Implemented in perl.
- csize
(gzip'ed tarfile)
Counts total lines, blank lines, lines with comments, nonblank
noncomment lines, semicolons, and preprocessor directives in C
programs.
Written by Christopher Lott in 1994.
Implemented in C using lex.
- cyclo 2.0
(gzip'ed tarfile)
Analyzes cyclomatic complexity of a piece of ANSI C or C++ code.
Can generate a postscript flowgraph of the functions.
Written by Roger Binns in 1993.
Implemented in C++.
- hp_mas
(gzip'ed tarfile)
Mas is a maintainability assessment tool for analyzing C programs
that was developed under the sponsorship of Hewlett-Packard
Corporate Engineering at the University of Idaho in 1992.
Implemented in C.
- lc
(gzip'ed tarfile)
A tool to count lines of code in C files.
Written by Brian Marick in 1983 and updated 1992.
Implemented in C.
- lc2
(gzip'ed tarfile)
A tool to count lines of code in C and C++ files.
Ray Rizzuto derived this from lc (above) in 2004.
- metre 2.3
(gzip'ed tarfile)
A rule-based software metrics tool for standard C.
Written by Paul Long in 1994.
Implemented in C.
- metrics
(gzip'ed tarfile)
A collection of tools (control/halstead/kdsi/mccabe).
Collected and written by Brian Renaud around 1989.
Implemented in C.
- sloccount
(gzip'ed tarfile)
Tools for counting lines in many (many) languages.
Written by David Wheeler in 2000.
Implemented in shell, perl, and C.
- spr
(gzip'ed tarfile)
A tool to measure NCSS for C source programs.
Written by Ted Shapin in 1989.
Implemented in C.
About building and using the tools in the collection:
I sucessfully built all of them using gcc/g++ on a sun running SunOS 4.1.3.
The authors of packages `c_count', `csize', `metre', and sloccount went to
considerable trouble to write portable code and flexible Makefiles.
The `hp_mas' package also includes well-documented Makefiles. For
`cyclo' and `metrics', no such effort was made, and consequently I had
to monkey with some makefiles. Packages `ccount', `clc', `lc', and
`spr' are relatively simple and should not present many problems.
Other Tools
Here are a few links to tools not archived here.
I have not used all of the tools extensively, so unfortunately I can't
make any helpful statements about reliability or ease of use.
Contact me