MaJerle/c-code-style logo

MaJerle/c-code-style

Free

Recommended C code style and coding rules for standard C99 or later

FreeFree tier
Type
Open Source

About MaJerle/c-code-style

A comprehensive C code style guide for C99 and later (C11 recommended) by Tilen MAJERLE. The repository provides detailed coding rules, conventions, and best practices for writing clean, consistent C code. It includes configuration files for clang-format, Artistic Style (astyle), and Eclipse CDT formatter, enabling automatic code formatting. The guide covers naming conventions, comments, functions, variables, structures, enumerations, typedefs, compound statements, switch statements, macros, and preprocessor directives. It also offers VSCode integration instructions using the built-in clang-format tool, and includes template source files for headers and implementations. The project is licensed under MIT and hosted on GitHub.

Key Features

Comprehensive coding style guidelines for C99 and C11
Configuration files for clang-format, Artistic Style (astyle), and Eclipse formatter
VSCode integration with auto-format on save
Covers naming, comments, functions, variables, structures, enums, typedefs, macros, and more
Template source files (template.c, template.h) included
Open source (MIT license) with 1.3k stars and 264 forks

Pros & Cons

Pros
  • Well-documented with a logical structure and table of contents
  • Includes practical configuration files for multiple popular formatters
  • Emphasizes the single most important rule: imitate the surrounding code
  • Active and maintained (over 100 commits, recent updates)
  • Open source and free to use under MIT license
Cons
  • Opinionated style may not suit all projects or teams
  • Focuses only on C, not applicable to other languages
  • Requires manual adoption and setup of the provided formatter configs

Best For

Standardizing C code style across a team or projectOnboarding new developers with consistent formatting rulesAutomating code formatting in CI/CD pipelines using clang-formatLearning best practices for writing readable and maintainable C codeSetting up editor integration (VSCode, Eclipse) for real-time formatting

FAQ

What is the single most important rule when writing code?
Check the surrounding code and try to imitate it. Consistency with existing code is paramount.
Does the project include configuration for clang-format?
Yes, the repository provides an up-to-date .clang-format file with rules matching the documented style.
What version of C is recommended?
The guide recommends using the C11 standard and the clang-format tool (version 15.x or higher).
Does it support integration with VSCode?
Yes, VSCode has built-in clang-format support. By placing the .clang-format file in the project root, code is auto-formatted on save.