PricingDownload
Product

Platform

All features44 capabilities, from IDE to CICompliance KitsISO 26262, DO-178C, IEC 62304...AI GovernanceControl AI-generated C/C++ codeWhat’s new in 2027Latest version highlightsScreenshotsSee the product in action

Analyze & improve

Coding standardsMISRA, CERT, CWE, AUTOSARArchitecture & dependenciesGraphs, matrix, cyclesTechnical debtMeasured in hours and dollarsQuality gatesStop regressions in CISmart Code CityYour codebase in 3D

Integrations

IDE pluginsVisual Studio, VS Code, CLion...CI/CD pipelinesJenkins, Azure DevOps, GitHub, GitLabSonarQube pluginC/C++ results in SonarQubeExternal analyzersClang-Tidy, Cppcheck, coverageFeature on Demand
Solutions

By need

Functional safetyCompliance kits per standardCoding standardsMISRA, CERT, AUTOSAR, ISO...Legacy modernizationRefactor large C/C++ safelyCode auditExpert review of your codebaseM&A due diligenceAssess technical health fast

By role

DevelopersSoftware architectsTech leadsDevOps engineersEngineering managersProject managers

CTOsCIOs / IT leadersQA engineersSecurity leadersComplianceConsultantsRequest a guided PoC
Industries

Safety-critical

AutomotiveISO 26262, MISRA, AUTOSARAerospace & DefenseDO-178C programsMedical DevicesIEC 62304 softwareEnergy & UtilitiesIEC 61508 systemsEmbedded SystemsFirmware and devices

Enterprise

Financial ServicesTrading and paymentsGame DevelopmentEngines and large C++Software VendorsCommercial C/C++ productsGovernmentAgencies and contractorsAll industries & case studies
Resources

Learn

DocumentationGuides, rules and CI setupKnowledge baseFrequently asked questionsBlogC and C++ code quality articlesRelease notesEvery version since 2009

Customers

Case studiesSuccess storiesTestimonialsWhat users sayOur customersCompanies using CppDependGold Code QualityOpen source projects we rate

Programs & company

Feature on DemandMissing features built for freeFree for open sourceLicenses for OSS and studentsContact usSales and supportEULALicense agreement
Docs
Documentation

User Guides

Dependency Matrix (DSM)

The Dependency Structure Matrix shows the dependencies between code elements as a table. It stays readable with hundreds of elements, which makes it the tool of choice to find dependency cycles and to check the layering of a large code base. This page explains every control, menu and action of the screen, with screenshots of a real analysis of Cppcheck 2.22.

9 min readUser GuidesCppDepend 2027

What the matrix shows

The same code elements are listed on the rows (left) and on the columns (top). The cell at the crossing of a row and a column describes the dependency between those two elements:

  • its color tells the direction of the dependency, or a cycle;
  • its number is the weight of the dependency, by default the number of members used;
  • an empty dark cell means no dependency.

A graph with 60 namespaces and their arrows is unreadable; the same 60 namespaces in a matrix fit on one screen, and cycles stand out as red blocks.

DSM of the Cppcheck application namespaces
The namespaces of Cppcheck in the matrix. The red frame groups namespaces caught in dependency cycles.

Opening the matrix

FromHow
Menu barDesign & Architecture › DSM.
Features panelDesign & Architecture › DSM.
Code Quest (query results)Export › Export to matrix, Export to matrix rows or Export to matrix columns. See Show a query result in the matrix.
Call GraphThe Export to matrix button opens the elements of the graph in the matrix.

The page title in the top bar reads DSM. The matrix opens on the projects of the solution; Cppcheck shows cli, cppcheck and two groups of third-party code, Externals and Windows SDK.

DSM at project level
The first view: projects and third-party code.

The screen at a glance

The numbers in the screenshot match the table. Controls 1 to 17 form the toolbar; 18 to 21 are the areas of the matrix. The tooltip column quotes the text shown when you hover the control.

DSM screen with numbered callouts
The DSM screen, numbered.
#ControlTooltipWhat it does
1View menuChoose what the matrix showsProjects or namespaces, with or without third-party code. See View menu.
2TriangularizeTriangularize the dependency matrixReorders rows and columns to reveal the layering. See Triangularize.
3Remove menuRemove empty rows / columnsShrinks the matrix. See Remove menu.
4Swap menuSwaps or copies the headers. Greyed out until the matrix can be changed this way. See Swap menu.
5UndoCancels the last change of the matrix (triangularize, remove, swap...). Greyed out when there is nothing to undo.
6RedoApplies again a change you undid.
7Export to Graph menuExport to GraphOpens the elements in the Call Graph. See Export menus.
8Save as PNG (camera)Save the matrix as a PNG imageSaves the matrix as an image file.
9Zoom OutZoom OutMakes the cells smaller, to see more of the matrix.
10Zoom valueThe number displayed between the two zoom buttons (19 here).
11Zoom InZoom InMakes the cells larger, to read the numbers.
12WEIGHT menuWhat the number in each cell countsMembers, methods, types... See Weight.
13Direct dependenciesDirect dependenciesCounts only direct uses (default, highlighted).
14Direct and Indirect dependenciesDirect and Indirect dependenciesAlso counts uses through other elements.
15BIND: don't bindDont bind Columns and RowsRows and columns can be changed separately (default, highlighted).
16BIND: bindBind Columns and RowsThe columns follow the rows: expanding or removing a row does the same on the matching column.
17Details tooltip (bulb)Show details tooltip on hoverSwitches the hover card on (highlighted, default) or off.
18LegendThe meaning of the colors, and the reminder "Right click: For more actions". See Colors.
19Column headersThe elements of the columns, grouped under their project. The + box expands an element into its children; − collapses it.
20Row headersThe same elements on the rows, with the same + / − boxes. Projects are written vertically on the far left.
21MatrixThe cells. The diagonal line marks where a row meets the same element in the columns.

The bars between the headers and the matrix can be dragged to give more room to the names.

Colors and numbers

CellMeaning (as given by the legend)
BlueRow uses column.
GreenColumn uses row.
RedCycle: both elements use each other. The first cell of a group of elements in a cycle carries a red corner mark, and a red frame surrounds the whole group.
Hatched grayNot visible to each other: the two elements cannot depend on each other.
Dark, no numberNo dependency.
Diagonal lineThe row and the column are the same element.
Small red corner with +Shown when a baseline is set (here Cppcheck 2.15): the dependency is new since the baseline.
Bold header nameShown when a baseline is set: the element is new or changed since the baseline.

The number is the weight of the dependency (see Weight). The brighter a blue or green cell, the heavier the dependency. To be sure of the direction of a dependency, hover the cell: the card states it in a sentence, such as uses 16 member(s) from.

View menu

View menu
The View menu.
ItemRows and columns are
View ProjectsAll projects, including the third-party groups (default).
View Application Projects OnlyYour projects, without third-party code.
View NamespacesAll namespaces, including third-party ones.
View Application Namespaces OnlyThe namespaces of your code. This is the view used in most screenshots of this page.

Triangularize

Click Triangularize (2) to reorder the rows and columns so that most dependencies fall on one side of the diagonal. Elements used by many others move to one end, elements that use many others to the other end: the order becomes the layering of your code. What remains on the wrong side of the diagonal, and every red cell, is a layering violation or a cycle.

Triangularized matrix
After Triangularize: the cycle blocks are grouped along the diagonal.

Use Undo (5) to go back to the previous order.

Remove menu

Remove menu
The Remove menu.
ItemEffect
Remove Empty Rows and ColumnsRemoves every row and column without any dependency.
Remove Empty ColumnsRemoves only the empty columns.
Remove Empty RowsRemoves only the empty rows.
Remove Rows with third-party code elementsKeeps only your code on the rows.
Remove Rows with application code elementsKeeps only third-party code on the rows: useful to see which libraries are used.
Matrix after Remove Empty Rows and Columns
After Remove Empty Rows and Columns: only namespaces involved in a dependency remain.

Swap menu

Available once the rows and columns differ, for example after opening a dependency.

Swap menu
The Swap menu.
ItemEffect
Swap HeadersThe rows become the columns and the columns become the rows.
Copy Vertical Headers to horizontal HeaderThe columns get the same elements as the rows.
Copy Horizontal Headers to Vertical HeaderThe rows get the same elements as the columns.
Matrix after Swap Headers
After Swap Headers: the ValueFlow types are now on the rows.

Weight: what the numbers count

Weight menu
The WEIGHT menu.
WeightThe number in a cell is
Direct & indirect depth of useHow far apart the two elements are in the chain of uses: 1 for a direct use, more through other elements.
Direct: # namespacesThe number of namespaces used.
Direct: # typesThe number of types used.
Direct: # membersThe number of members (methods and fields) used. This is the default.
Direct: # methodsThe number of methods used.
Direct: # fieldsThe number of fields used.

The two buttons after the menu (13, 14) choose between Direct dependencies and Direct and Indirect dependencies. With indirect dependencies, an element that reaches another one through intermediate elements also gets a cell.

Hovering a cell

With the bulb (17) on, hovering a cell shows a details card:

Hover card of a cycle cell
A red cell: the global namespace of cli and anonymous_namespace{cppcheckexecutor.cpp} use each other.
  • The row and the column of the cell are highlighted with a golden band, and the cell gets a golden border.
  • Golden labels give the full names of the row element and of the column element.
  • The card shows both elements with their LOC, Debt, Rating (A to E) and MI (maintainability index).
  • Between them, a sentence states the dependency: has dependency cycle with for a red cell, uses N member(s) from otherwise. The arrow shows the direction.
  • The footer reminds the actions: Double Click Show Dependencies Details, Right Click Advanced Actions.
Hover card of a blue cell
A one-way dependency: the card reads uses 1 member(s) from.
Right-click menu of a cell
The right-click menu of a cycle cell.
ItemWhat it does
Build a Graph made of Code Elements involved in this dependencyOpens the Call Graph with the elements that create the dependency.
Open this dependency (bold: same as double-click)Opens a new matrix with the children of the two elements, to see exactly which types or members are involved.
Open this dependency (keep only involved dependencies)
or Open this cycle (keep only involved dependencies) on a red cell
Same, but keeps only the elements that take part in the dependency or the cycle.
Edit a code query that matches this dependencyOpens Code Quest with a generated CQLinq query that selects the elements of the dependency.
Generate a code rule that warns if this dependency existsCreates a rule that reports an issue while the dependency exists. Use it to forbid a dependency that breaks your architecture, and enforce it with quality gates in CI.

Open this dependency

On the cell where anonymous_namespace{programmemory.cpp} uses 16 members from ValueFlow, Open this dependency shows the types behind it: assign and Executor on the rows, the ValueFlow types (Value, Value+Bound, Value+ValueType...) on the columns.

Matrix opened on one dependency
One dependency, opened: which types use which.

Edit a code query that matches this dependency

Code Quest opens a Generated Query tab. For the cycle cell above, the query selects the namespaces that use or are used by anonymous_namespace{cppcheckexecutor.cpp} at depth 1, and returns 2 namespaces. Edit it, run it, or save it as a rule.

Generated query in Code Quest
The generated CQLinq query and its result.

Export menus

Export to Graph menu
The Export to Graph menu.
ItemOpens in the Call Graph
Export Elements To GraphAll the elements of the matrix.
Export Horizontal Header To GraphThe elements of the columns.
Export Vertical Header To GraphThe elements of the rows.

The camera button (8) saves the matrix as a PNG image, for a report or a design review.

Show a query result in the matrix

In Code Quest, run a query that returns code elements, then open Export above the result grid:

ItemResult
Export to matrixThe result elements on both rows and columns: how they depend on each other.
Export to matrix rowsThe result elements on the rows only.
Export to matrix columnsThe result elements on the columns only.

Then use Remove Empty Rows and Columns to keep the elements that really depend on each other, and Triangularize to order them.

Recipes

QuestionSteps
Which namespaces are in a cycle?View › View Application Namespaces Only, Triangularize, look for red cells and red frames.
What creates this cycle?Right-click the red cell › Open this cycle (keep only involved dependencies).
Is my layering respected?Triangularize; cells left on the wrong side of the diagonal are upward dependencies.
Forbid a dependencyRight-click the cell › Generate a code rule that warns if this dependency exists.
Which libraries does my code use?View Namespaces, then Remove › Remove Rows with application code elements.
Make a big matrix readableRemove Empty Rows and Columns, Zoom Out, collapse groups with the − boxes.
See it as a diagramExport to Graph › Export Elements To Graph.

Related pages

Was this page helpful?
Evaluating CppDepend on a production codebase?Get a guided proof of concept with our static analysis architects.
Request a PoC