Automating Quality Checks with CCCC-C and C++ Code Counter

How to Use CCCC-C and C++ Code Counter for Accurate Code Analysis

1) Install and run

  • Install from your package manager (e.g., apt install cccc) or build from source (github.com/sarnold/cccc).
  • Run on your project root:

    Code

    cccc src/.c src/.cpp include/*.h –outdir=metrics_output
  • Default output: HTML site in .cccc (or the directory set via –outdir).

2) Key options to set

  • –outdir=DIR — where reports go.
  • –html_outfile=FILE — main HTML report filename.
  • –lang=LANG — force language parsing (c, c++, java).
  • –report_mask=HEX — control which metrics appear (useful for custom reports).
  • –opt_infile/–opt_outfile — load/save option presets.

3) Important metrics CCCC produces

  • Lines of Code (LOC) — module/file and total counts.
  • Cyclomatic Complexity (McCabe) — function/module complexity; higher = harder to test/maintain.
  • Fan-in / Fan-out — coupling indicators (higher fan-out often signals high responsibility).
  • Object-oriented metrics (for C++): inheritance depth, class-level measures.
  • Module counts and simple size metrics.

4) How to interpret results for accuracy

  • Treat LOC as a size indicator only—normalize by module or feature.
  • Use cyclomatic complexity thresholds (suggested practice):
    • 1–10: simple, low risk
    • 11–20: moderate complexity — review
    • 21+: high complexity — refactor or add tests
  • Look for files with high LOC + high complexity + high fan-out — prioritize these for refactor/testing.
  • Compare metrics trends over time (use saved DB file via –db_outfile) instead of single snapshots.

5) Integrate into workflow

  • Add CCCC to CI (run on pull requests) and fail or warn on preset thresholds.
  • Generate HTML output as an artifact for developer review.
  • Store and diff cccc.db between runs to detect regressions.

6) Practical tips

  • Use –lang when extensions are ambiguous.
  • Exclude generated code or third-party libs from analysis to avoid noise.
  • Combine CCCC output with unit-test coverage and code-review results for balanced decisions.
  • For large projects, run in parallel over subtrees and merge results into a single outdir.

7) Troubleshooting

  • If parsing fails on modern C++ idioms, try latest CCCC from GitHub or pre-filter problematic files.
  • Use verbose/debug options (debug_mask) during config to see parser issues.

References: CCCC project on GitHub (sarnold/cccc) and its user guide/man page for option details.

Comments

Leave a Reply

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