 |
C/C++ Source Code Counter Program
---------------------
Program Features |

What This Program Counts
The retiSoft Source Line of Code (SLOC) Counter program supports
two generally accepted practices for counting SLOC:
- "Semicolon Counts": Many structured programming languages,
such as C/C++, Java, Pascal, and Ada, terminate logical statements
with a semicolon. It is fairly common practice in the software
industry to parse a source code file for the number of semicolons
encountered and to use it as the measure of program size.
The retiSoft SLOC Counter program counts statement terminating
semicolons to provide a logical statement count.
The program specifically excludes from this count:
- Semicolons found within either C or C++ style comments.
- Semicolons used within programming constructs, such as in the
C/C++ for iteration construct.
- Counting Framework Elements: The retiSoft Source
Line of Code (SLOC) Counter program supports user defined application of SEI SLOC counting framework. The types of
code lines counted include:
- Total Lines: The number of physical lines in
the file being analyzed. This number corresponds to the
traditional card image lines of code.
- Completely Blank Lines: It is common (and desirable)
to place blank lines before and after various sections of
code or comments in a source code file to make them stand
out and easier to find and read. Many company coding
standards require the use of blank lines to create
"white space" that enhances readability. Although
these blank lines are a desirable part of the code file,
they are seldom included in SLOC counts.
- Compiler Directive Lines: C/C++ compilers support
preprocessor directives that provide instructions to
the compiler. These directives begin with the "pound
sign" (i.e., "#"). Some of the most frequently
used are:
#include, #define, and #ifdef or
#ifndef. Because such directives often require the same
engineering effort as declaration and executable statements
(e.g., using a #define directive to declare a constant
or a macro in lieu of a function), they are typically included
in SLOC counts.
- C++ Comment Lines: Non-executing comment statements
are an essential part of any program source code file. They are
probably the most critical element in providing long-term support
for a program; correcting latent defects or adding new features.
Besides providing needed program identification and configuration
management information, comments describe what sections of code
are to do, why a particular approach was selected (or an
"unusual" implementation was used), or how the code can
be modified to change its characteristics. Although comments add
significant value to the source file, they are often excluded in
SLOC counts because they do not directly affect the program
execution. One company I once worked for included comments at a
10% weighting in the SLOC count (i.e., every ten comments counts
the same as one declaration or executable statement). This program
includes physical lines that have only a C++ style comment on them
in this count.
- Declaration & Executable Lines: These are the program
statements that are translated by the compiler into executable
instructions or allocate memory storage for data and determine how
the data can be accessed. Universally these lines are included in
the SLOC counts.
As mentioned above, comments are an essential element of good
programming practices. In fact, a commonly used measure of software
quality is the ratio of comments to the counted SLOC. Although I am
not aware of any standards for this, I have observed ratios of 1:3 to
1:2 (i.e., one comment for every 2 to 3 SLOC) being accepted as
representing a well commented program that promotes its maintainability.
The C++ Comment Lines described above refer to only physical
lines that contain only a C++ style comment (i.e., one that begins with
"//"). In addition to this category, the retiSoft SLOC
Counter program also provides counts for other types of comments.
- Lines with C++ Comments too: In addition to lines
that contain only a C++ comment (as described above), the
programmer can append a C++ comment to the end of other source
lines, such as declaration and executable lines. Although these
physical lines are counted in other categories listed above,
the presence of the comment needs to be considered when counting
comments for other purposes.
- Total C++ Comments: This is merely the sum of
the count of C++ comments that are the only contents of a line
and the count of C++ comments that are appended to the end of
a line that was otherwise counted.
- C-Style Comments: In addition to C++ sytle
comments, most C++ compilers also support the older C-style
comments (i.e., those beginning with "/*" and ending
with "*/"). The retiSoft SLOC Counter program
counts C-style comments in addition to C++ style comments.
The program correctly handles C-style comments that span multiple
physical lines as a single comment. It also processes nested
C-style comments (i.e., one C-sytle comment within the scope of
another) by counting only the outer-most of them.
The following illustrates the format used by the retiSoft SLOC Counter
program to report the data described above.
=======================================
Source File:
Path: <path to subject file>
Filename: <filename>
These data collected on: <date>
Semicolon Count: <count>
Physical LOC (by category):
Total Lines: <count>
Completely Blank Lines: <count>
Compiler Directive Lines: <count>
Lines with only C++ Comments: <count>
Declaration & Executable Lines: <count>
Additional Comments Data:
Lines with C++ Comments too: <count>
Total C++ Comments: <count>
C-Style Comments: <count>
=======================================
The retiSoft Source Line of Code (SLOC) Counter program also provides an
option to output the gathered data at one file per line to a comma-delimited
text file that can be imported to a common spreadsheet program, such as
Microsoft Excel, for further analysis or charting. The included help file
provides specific instructions for importing such a comma-delimited file into
the provided Microsoft Excel "template" file.
C/C++ Source Code Counter Program Change History
| Version |
Release Date |
Description |
| 1.1.1 |
17 July 2001 |
Initial release. |
...return to the
retiSoft Products page

retiSoft inc. is a member of the
Association of Shareware Professionals
(ASP). ASP wants to make sure that the shareware principle
works for you. If you are unable to resolve a shareware-related problem with
an ASP member by contacting the member directly, ASP may be able to help. The
ASP Ombudsman can help you resolve a dispute or technical problem with an ASP
member, but does not provide technical support for members' products. Please
contact the ASP Ombudsman online at
http://www.asp-shareware.com/omb.