GNU Complexity Command Line Tool Measures Complexity of C Code

GNU complexity is a command line tool that computes a complexity measure of C source code, similar to pmccabe, but with a different method of calculating results with short functions scoring lower than pmccabe and highly nested functionality can score considerably higher. It can be useful to locate suspicious areas in unfamiliar code, get an idea of the efforts required to either understand the code or test it, or self-assess your own code.

Bruce Korb, the maintainer, has just released version 1.5 with some bug fixes, so I’ve given it a quick try.

We’ll need to get the code, build and install it first:

The user’s manual provides some insights and an example, which I’ve used against a directory in Linux source code:

The resulting table shows six information per line: the computed score, the number of lines between the opening and closing curly braces (ln-ct), the number of non-comment, non-blank lines found there (nc-lns), the name of the source file, the line number of the opening curly brace, and the name of the procedure. The higher the score the more complex is the procedure, and thres parameter is used to remove the lowest complexity function from the list. The ranking goes as follows:

  • ‘0-9’ – Easily maintained code.
  • ‘10-19’ – Maintained with little trouble.
  • ‘20-29’ – Maintained with some effort.
  • ‘30-39’ – Difficult to maintain code.
  • ‘40-49’ – Hard to maintain code.
  • ‘50-99’ – Unmaintainable code.
  • ‘100-199’ – Crazy making difficult code.
  • ‘200+’ – I only wish I were kidding.

Have fun.

Share this:

Support CNX Software! Donate via cryptocurrencies, become a Patron on Patreon, or purchase goods on Amazon or Aliexpress

ROCK 5 ITX RK3588 mini-ITX motherboard
Notify of
The comment form collects your name, email and content to allow us keep track of the comments placed on the website. Please read and accept our website Terms and Privacy Policy to post a comment.
8 years ago

This was news to me. Thanks so much for sharing.

8 years ago

, which font is used in the shell (output)? Is it a monospaced font?

Khadas VIM4 SBC