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:
FacebookTwitterHacker NewsSlashdotRedditLinkedInPinterestFlipboardMeWeLineEmailShare

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

4 Replies to “GNU Complexity Command Line Tool Measures Complexity of C Code”

  1. I’ve run “complexity” again against across the complete linux kernel source and the most complex function according to the tool is:

Leave a Reply

Your email address will not be published. Required fields are marked *

Boardcon Rockchip and Allwinner SoM and SBC products
Boardcon Rockchip and Allwinner SoM and SBC products