How can I get the cyclomatic complexity for functions and not for files in c?

When i look at the measures in SonarQube i got the cyclomatic complexity on file base.

I need this metric on function base. How can i get this information?

Best regards

Volker

Hi Volker,

Welcome to the community!

We don’t record metrics below the file level. If you really need this (why?) then you’ll have to tune the FunctionComplexity threshold to 1, and read the values from the issue messages. Of course, the unpleasant side-effect will be that you raise an issue per function. You can tune the rule down to Info level to make this slightly less unpleasant, but… it is what it is.

 
Ann

Hello Ann,

the usage of the metrics of function level (McCabe) are required from the standards for safety development like the IEC 61508 and also from the assessors from the TUEV, when the are involved in a certification process for safety products.

Shure it is possible to use the FunctionComplexity, but an overview over all the function inside the measures will be nice.

Best regards

Volker

Hi Volker,

Thanks very much for sharing. It’s quite interesting to know that this is related to safety standards.

To be clear, and not to promise anything at all (because there’s not much chance, TBH), when you say this:

are you saying that you’d like a list of function complexity values at the file level, e.g. here:

Or in the project-level Measures space?

 
Thx,
Ann

Hello @vokuit00,

Could you be a little bit more explicit about what are your requirements for safety wrt cyclomatic complexity?

From what I get from the safety world, I would expect the following situation:

  • You have to prove that you check the cyclomatic complexity of all functions,
  • You have to avoid any function with a cyclomatic complexity higher than some threshold, unless this function has a very good reason to, and has been specially reviewed and approved by a safety expert.

This is exactly what the rule https://rules.sonarsource.com/cpp/RSPEC-1541 allows you to do.

You seem to imply that you have a different need, but this need is not clear to me. Do you simply need a static report of all functions and their corresponding complexity? Do you need the capability to drill-down? To make cross comparison with other metrics? Something else?

Does the standard you refer to give an accurate definition of cyclomatic complexity, or can any reasonable definition work? (The definition for C code is pretty standard and unambiguous, which is far from the truth for C++ code, for instance how to count lambdas or exceptions?)

Thank you,

At file level, as shown in your picture, will be perfect.

Hello JolyLoic,

I have the same needs, but it would be nice to have an overview to be able to recognize in time that a function will soon reach the limit.

I need no comparison. Typically McCabe is used as cyclomatic complexity value.

Best regards

Volker

Hi Volker,

Thanks for getting back to me. FYI, I’ve moved this to the ‘Suggest new features’ category since you’re asking for something that doesn’t exist.

 
Ann