Lesson 47 of 50 · c
Static Analysis with clang‑tidy
Duration: 9 mins
clang‑tidy is a linter that checks C code for bugs, style, and modern practices.
Common checks:
readability-identifier-naming– enforce naming conventions.modernize-use-nullptr– (C++) not applicable, butmodernize-*offers suggestions for C as well.bugprone-*– detect potential undefined behaviour.performance-*– recommend faster constructs.
Typical command:
clang-tidy src/*.c -checks='*' -warnings-as-errors='*' -- -Iinclude
The -- separates clang‑tidy options from compiler flags.
📚 Example Output
src/main.c:12:5: warning: use of uninitialized variable 'x' [clang-analyzer-core.Uninitialized]
int result = x * 2;
^~~~
1 warning generated.