|
|
A programmer may have a strong influence over the manner in which a program is constructed. Some programmers use many comment statements to document their activities. Other programmers think that their code must be self-explanatory. Some programmers tend to write very short statements while others might implement the same design specification in very few lines. Some programmers are very terse in their use of declarations. Other programmers will be very expressive with their use of declared variables. The first class of metrics we wish to define are those that relate to the frequency of use of comments, executable program statements, and nonexecutable statements.
Comments are delimited by "/*" and "*/". Each occurrence of the comment delimiter pair is counted. Global comments will not be counted. They are clearly outside the scope of any function module. Nested comments and comments delimiters found within comment strings are ignored.
The character ';' is used to delimit some statements in C. An executable statement is a statement that will change the state of the program at runtime. In C, executable statements can stand alone, in which case they are delimited by <;>. They can also be embedded in predicate clauses such as:
while (j = k < 1)
in which case they are delimited by <)>. They can also occur in declarations, such as:
{ int j = 1, k = 2; }
In this case, the statement j = 1 is delimited by <,>.
A compound statement delimited by <{> and <}> may or may not contain declarations within its body. If it does contain declarations, it is a block. The declarations that differentiate a block from a compound statement will cause the compiler to build an activation stack at runtime. Therefore, a block is an executable statement in its own right.
The executable statement count must not be modified in the following cases (see Exhibit 1):
Within a string constant
Within a character constant
Within a comment
At the end of a nonexecutable statement
As a separator in a for structure
Exhibit 1: Examples with Executable Statements
Examples | Executable Statements |
---|---|
int a; a = b + c; for (i = 1; I<50; i++) b[i] = ' ; '; while (a=b<c) a++; | 0 |
1 | |
4 | |
2 | |
Nonexecutable statements are present in variable declarations, structures, unions, enumerated declarations, and type definitions. If a variable is declared, the declaration is considered a nonexecutable statement. Very simply, nonexecutable statements will not result in executable code at runtime.
The nonexecutable statement metric must not be modified in the following cases (see Exhibit 2):
Within a string constant
Within a character constant
Within a comment
Type definition
Exhibit 2: Examples with Nonexecutable Statements
Examples | Nonexecutable Statement |
---|---|
int i ; int i = 3; typedef int bool; struct time { int hour; int minute; }; typedef struct time { int h our; int minute; }timetype; timetype a, b, *c; | 1 |
1 | |
1 | |
3 | |
4 | |
|
|