Cyclomatic complexity measure for C/C++

Information:

  • SonarQube: 10.6 Developer Edition
  • SonarScanner: sonar-scanner-cli-6.1.0.4477-linux
  • Language: C

Is it possible to view the cyclomatic complexity of individual functions? The cyclomatic complexity measure looks to be the sum of complexities of all files. But for the code I would like to analyse we have a requirement of cyclomatic complexity at the function level.

Hi @nathancsys,

I don’t know of any way to get the cyclomatic complexity of functions.
However, you can identify functions which complexity exceed a defined threshold by enabling rule c:S1541 The cyclomatic complexity of functions should not be too high.

Hi,

To build on @Bachri_Abdel’s excellent answer, if you really want to see the complexity of each function, then it’s painful but doable. Use the rule he mentioned and set the threshold to 0. Since Cyclomatic Complexity “charges” 1 simply for having a method/function, you’ll get an issue on every single function and the issue message will tell you its complexity.

 
HTH,
Ann