Content health: prewriting stage
This chapter is not yet finished. To speed up the progress, help us fix it at GitHub.

Coding style

C doesn't have standards or official guidelines when it comes to code writing style. Having such freedom is many times useful and also important, however collaborating on a project with different developers will soon require a set of coding style guidelines. Important to understand here is that no matter which coding style you pick, define it well and stick to it when adding new code. Reading code with consistent coding style matters.

Here are top coding styles you should consider adopting instead of reinventing your own.

Useful tools


Clang-Format is a very useful formatting tool to quickly format your C code to a predefined coding style.

Main tool is clang-format. You initially create a YAML file called .clang-format in your project root directory with definitions how formatting should be done.

Read documentation about Clang-Format on the official page. This tutorial only serves as a guideline on which tools you should use.


One part is formating existing code. Another part is formating code as you code. Many editors and IDEs will have predefined coding standards already available, and for more there is Editorconfig, a project where you can set coding style per project basis. The file .editorconfig with INI syntax includes definitions for files and which coding standards should be used. Most of todays editors and IDEs support EditorConfig via plugins or have support already built in.

Found a typo? Something wrong with this content?

Just fork and edit it.

Content of this work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license. Code snippets in examples are published under the CC0 1.0 Universal (CC0 1.0). Thanks to all contributors.