c-code-style
Skill1.4k starsChanged 4 months agoMITView on GitHub
Write, edit, or review C (and C-compatible header) code according to C coding style rules, then check and run clang-format to enforce formatting. Trigger on "write C code", "edit a .c/.h file", "review C code style", "format C code", "run clang-format", "check clang-format", "apply the C style guide".
- Installs packages
Trending
Quiet this year.thin dataabout the whole repository
Who's talking about MaJerle/c-code-style
- lwvmobile/dsd-fme“Refactor: Modular RTL‑SDR FM pipeline with unified device control, accurate rate chain, and cooperative …”GitHub · Sep 11, 2025
- DavitMelikyan/Homework“Consistent C Coding Style”GitHub · Mar 24, 2025
- sw33tdreams/C_projects“Consistent C Coding Style”GitHub · Mar 22, 2025
- DavitMelikyan/Homework“Consistent C Coding Style”GitHub · Mar 22, 2025
- Gevorg-Mkrtchyan7/Control-Structures“Consistent C Coding Style”GitHub · Mar 22, 2025
The biggest 5 of 6 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 6
Talked about on GitHub (6 times).
On GitHub · 6
- Sep 11, 2025Refactor: Modular RTL‑SDR FM pipeline with unified device control, accurate rate chain, and cooperative retune/shutdown. Attempts to fix NXDN demodulation. — lwvmobile/dsd-fme0 reactions · 1 comment
- Mar 24, 2025Consistent C Coding Style — DavitMelikyan/Homework0 reactions
- Mar 22, 2025Consistent C Coding Style — sw33tdreams/C_projects0 reactions
- Mar 22, 2025Consistent C Coding Style — DavitMelikyan/Homework0 reactions
- Mar 22, 2025Consistent C Coding Style — Gevorg-Mkrtchyan7/Control-Structures0 reactions · 1 comment
1 more on GitHub
- Sep 14, 2022applied source code format from https://github.com/MaJerle/c-code-style — bontango/lisy-src-5.x0 reactions
In this repositoryOne other file it gives its agents.
- AGENTS.mdAGENTS.md
The file
We split this skill into the rules it gives an agent
9 rules. About 0 are common, 1 is distinctive, and 8 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
8
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 18
Before writing or editing C code, read CODING_RULES.md in this repository (or wherever this skill was installed alongside it — if it's not …
- Distinctive: line 27
Don't hand-format these — write reasonably and let the formatter normalize them in step 4: indentation and spacing, brace placement, …
- Very specific: line 40
Use stdint.h types (uint8_t, int32_t, ...) except char/float/double.
- Very specific: line 41
Avoid stdbool.h; use 1/0.
- Very specific: line 42
Don't rely on static initializers for global/static variables that need a real startup value in embedded contexts — give the module an …
- Very specific: line 50
Every function with zero parameters uses (void), never empty ().
- Very specific: line 54
Check a pointer against NULL before dereferencing it (unless the surrounding code guarantees it can't be NULL).
- Very specific: line 70
After writing or editing any .c/.h file, run the formatter using this repository's .clang-format (it's found automatically by walking up …
- Very specific: line 82
If missing or too old, prints the install command for the current OS (brew install llvm on macOS, distro package or LLVM apt repo on Linux, …
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
C code style
This skill applies whenever you are writing, editing, or reviewing .c or .h
files in a project that adopts this style guide. The full rule set lives in
CODING_RULES.md at the repository root — that
file is the single source of truth (this repository's README.md is just a
symlink to it, so it renders on the GitHub front page). This skill exists to
make the rules operational: what to self-apply while writing code, and how to
run the formatter afterward.
1. Read the rules first
Before writing or editing C code, read CODING_RULES.md in this repository
(or wherever this skill was installed alongside it — if it's not there, the
checklist in step 3 below is a self-contained fallback). Do not rely on
memory of "typical" C style — several of this guide's rules are deliberately
non-default (e.g. (void) on zero-parameter functions, at most 2 return
points per function, no stdbool.h).
2. What clang-format fixes for you
Don't hand-format these — write reasonably and let the formatter normalize them in step 4: indentation and spacing, brace placement, pointer-asterisk alignment, function-prototype alignment, trailing commas in struct initializers, blank-line and parenthesis spacing.
3. What clang-format will NOT fix — apply these yourself while writing
These are semantic or naming rules; a formatter cannot infer them. Apply them as you write, not after:
- Names (variables, parameters, struct/enum members) are lowercase with
underscores and at least 3 characters. Never a bare
__/_prefix.staticmodule-private functions use aprv_prefix. - Use
stdint.htypes (uint8_t,int32_t, ...) exceptchar/float/double. Avoidstdbool.h; use1/0. - Don't rely on static initializers for
global/staticvariables that need a real startup value in embedded contexts — give the module aninit()function instead. - Declare all locals at the top of a block, grouped by type, in order: custom structs/enums (and their pointers) → integers (widest unsigned first) → floating point.
const-correct pointers and parameters; generic pointers arevoid*, cast internally, never cast avoid*return value.- Every function with zero parameters uses
(void), never empty(). - A function has at most 2
returnpoints: one early return for parameter/argument validation, one at the end. Noreturnin the middle — use a return-value variable to accumulate the result instead. - Check a pointer against
NULLbefore dereferencing it (unless the surrounding code guarantees it can't beNULL). Afterfree(ptr), immediately setptr = NULL. - Boolean-treated variables are compared with
if (x)/if (!x), never== 1/== 0; counter/value variables use> 0/== 0, never bareif (x). - Doxygen: every function (including
staticones) gets a\brief, a\param[in]/\param[out]per parameter, and a\returnif it returns non-void. The doc block goes at the function's definition (where the body is, typically the.cfile) — never duplicated at the declaration in the header. Pad tags so description text starts at column 22 (seetemplate.c/template.hfor the exact alignment). Wrap identifiers, constants, and literals referenced in prose in backticks.
4. Format the code
After writing or editing any .c/.h file, run the formatter using this
repository's .clang-format (it's found automatically by walking up from the
file's directory — no path needed):
scripts/check-format.sh <changed-file.c> [<changed-file.h> ...]This script:
- Checks
clang-formatis onPATHand is version20or newer (this repo's minimum — seeCODING_RULES.md, General rules). - If missing or too old, prints the install command for the current OS
(
brew install llvmon macOS, distro package or LLVM apt repo on Linux, the LLVM installer on Windows) and exits non-zero — install it, then re-run. - Otherwise runs
clang-format -ion the given files.
To verify compliance without writing changes (e.g. before reporting a task
done), use --check instead:
scripts/check-format.sh --check <file.c> [<file.h> ...]Exits 0 if already compliant, non-zero (with the specific violations) if
not.
5. Verified behavior
This flow was tested directly in this repository: check-format.sh correctly
refuses to run when clang-format is absent (prints the right install
command per OS and exits 1), and — once clang-format is installed —
correctly detects a deliberately mis-formatted file with --check, fixes it
with the default (in-place) mode, and re-verifies clean afterward.
template.c and template.h in this repository both pass --check as-is —
use them as a reference for exact formatting and doxygen alignment.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

