C Coding Practices
Application skill for C style learning (from the archived awesome-guidelines style capsules). For Linux kernel or GNU projects, follow tree-specific style (tabs, 80 cols) when documented locally.
Core Principle
C quality is explicit scope, explicit control flow, explicit failures, the language will not save you from unclear names or unchecked returns.
When to Use / NOT
- C libraries, firmware, native extensions, syscall glue.
- Setting up clang-format, cppcheck, sparse, or static analysis in CI.
NOT when:
- C++ translation units, use
cpp-coding-practices.
- Generated bindings, validate generator output.
Workflow
- Format & control, K&R braces, Yoda
==, switch default (c-style-formatting-control.md).
- Naming, snake_case,
g_, pointers (c-style-naming-types.md).
- Headers, guards, extern/define split (
c-style-headers-modules.md).
- Macros & safety, parenthesized macros, init-all, error checks (
c-style-macros-safety.md).
- Verify, compiler warnings (
-Wall -Wextra), static analyzer on changed files.
Red Flags
- Uninitialized variables
- Variable definitions in
.h
char* a, b declarations
- Macros without parenthesized parameters
- Magic numbers in conditionals
- Unchecked
malloc/fopen/syscall returns
#ifdef DEBUG without defined value semantics
- Abbreviated global names
Verification
clang -Wall -Wextra -Werror (project policy)
- cppcheck / Coverity / sparse on changed TUs
- Link test: header included from multiple
.c files without duplicate symbols
- Capsule checklist on review
References
awesome-guidelines/references/c-style-learning-note.md
awesome-guidelines/references/c-style-formatting-control.md
awesome-guidelines/references/c-style-naming-types.md
awesome-guidelines/references/c-style-headers-modules.md
awesome-guidelines/references/c-style-macros-safety.md
1---2name: c-coding-practices3description: Use when authoring or reviewing C, snake_case naming, header guards, no data in headers, Yoda comparisons, safe macros, initialize-all, and checked error returns.4---56# C Coding Practices78Application skill for C style learning (from the archived `awesome-guidelines` style capsules). For Linux kernel or GNU projects, follow tree-specific style (tabs, 80 cols) when documented locally.910## Core Principle1112C quality is **explicit scope, explicit control flow, explicit failures**, the language will not save you from unclear names or unchecked returns.1314## When to Use / NOT1516- C libraries, firmware, native extensions, syscall glue.17- Setting up clang-format, cppcheck, sparse, or static analysis in CI.1819**NOT when:**2021- C++ translation units, use `cpp-coding-practices`.22- Generated bindings, validate generator output.2324## Workflow25261. **Format & control**, K&R braces, Yoda `==`, switch default (`c-style-formatting-control.md`).272. **Naming**, snake_case, `g_`, pointers (`c-style-naming-types.md`).283. **Headers**, guards, extern/define split (`c-style-headers-modules.md`).294. **Macros & safety**, parenthesized macros, init-all, error checks (`c-style-macros-safety.md`).305. **Verify**, compiler warnings (`-Wall -Wextra`), static analyzer on changed files.3132## Red Flags3334- Uninitialized variables35- Variable definitions in `.h`36- `char* a, b` declarations37- Macros without parenthesized parameters38- Magic numbers in conditionals39- Unchecked `malloc`/`fopen`/syscall returns40- `#ifdef DEBUG` without defined value semantics41- Abbreviated global names4243## Verification4445- `clang -Wall -Wextra -Werror` (project policy)46- cppcheck / Coverity / sparse on changed TUs47- Link test: header included from multiple `.c` files without duplicate symbols48- Capsule checklist on review495051## References5253- `awesome-guidelines/references/c-style-learning-note.md`54- `awesome-guidelines/references/c-style-formatting-control.md`55- `awesome-guidelines/references/c-style-naming-types.md`56- `awesome-guidelines/references/c-style-headers-modules.md`57- `awesome-guidelines/references/c-style-macros-safety.md`