Replies: 5 comments
-
Can you provide a reduced test case (or at least some example code)? As I mentioned in issue #10 there are cases where the parser rejects problematic code, and in the case of C it can be half the source tree. Also, see the cyclo tool for an independent calculation of function-level complexity. |
Beta Was this translation helpful? Give feedback.
-
Hi, I performed some tests regarding this issue and tried to understand why CCCC may calculate a MVG = 0. The test I'm using is trivial: #include <stdio.h>
// Simple Test functions
int func_a(int arg) {
return arg;
}
void func_b() {
return;
}
void func_c() {
return;
}
int main(int argc, char *argv[]) {
func_a(argc);
func_b();
func_c();
return EXIT_SUCCESS;
} The calculated MVG is one for each function, OK: In the next step I removed the return statement from the #include <stdio.h>
// Simple Test functions
int func_a(int arg) {
return arg;
}
void func_b() {
return;
}
void func_c() {
}
int main(int argc, char *argv[]) {
func_a(argc);
func_b();
func_c();
return EXIT_SUCCESS;
} The calculated MVG of I prepared a patch that the MVG complexity always begins with 1 and that an encountered |
Beta Was this translation helpful? Give feedback.
-
Good analysis; I wish all bug reports were this thorough. |
Beta Was this translation helpful? Give feedback.
-
Oh, and the answer to the original issue question is (theoretically) No. AFAIK a single piece of code with a single execution path (ie, no branches) has cyclomatic complexity of 1. |
Beta Was this translation helpful? Give feedback.
-
Hi Tim Littlefair, original author of CCCC here. |
Beta Was this translation helpful? Give feedback.
-
I found bunches of functions have MVG scored 0 which is conflict to my understanding of the Cyclomatic Complexity.
Besides the original/formal formula to calculate the complexity by referencing to the control flow graph, we can also calculate it by counting the number of decision points and using MVG = D + 1; (D stands for the number of decision points). Therefore, by definition, a function with zero decision points still supposed to get MVG =1, as the lowest score possible as well.
Beta Was this translation helpful? Give feedback.
All reactions