C Data Coupling is one of Understand's built-in reports — run it on your own code from the GUI, or headlessly with und report.
C Data Coupling
Languages: CTargets: Project
Documents data coupling between C modules: every link where data written in one module is read in another.
Output is one row per writer → reader link. Each source file is a module, and only links that cross a module boundary are listed. Only C code is analyzed: .c files and the headers they include. C++ sources, and headers only C++ sources include, are skipped.
Mechanisms:
- global – a file-scope or static object written in one module and read in another, directly or through a pointer that aliases it
- by_value – an argument passed by value
- by_ref – an argument passed through a pointer; the direction follows whether the callee reads or writes through it
- function_pointer – a function pointer passed as an argument
- return – a returned value that the caller uses
Coupling is tracked per whole object, not per struct field. Initializers are not run-time writes and are ignored. Requirement Ref and Test Ref are left blank for the analyst to fill in.
A write through a pointer is a write to the data it points to, not to the pointer: for a pointer global g, only g = ... writes g, while g->field = ... reads it.
Limitations:
- Calls made through function pointers cannot be resolved to a callee, so arguments and return values passed through them are not listed.
- Pointers stored in struct or union members are not followed, because a member is shared by every instance of its type.
- Pointer assignments made inside a macro expansion, such as
#define NORM(p) ((p) = (p) ? (p) : g_default), are not recorded in the database, so an alias created that way is not followed. Accesses through it, and the links they would create, are not listed.