C Beautifier

Format C code with clang-format.

0 chars
0 words
0 lines
0 chars
0 words
0 lines

C Beautifier – Format C Code Online

The C beautifier uses clang-format, the formatter that powers code style in the Linux ecosystem, LLVM, Chromium, and countless open-source C projects. It runs as WebAssembly in your browser, so you can format C code without installing anything.

What it formats

  • Preprocessor directives (#include, #define, conditional compilation) are kept in place.
  • Function definitions, structs, unions, enums, and typedefs.
  • Pointer declarations with consistent * placement for the chosen style.
  • Control flow (if, for, while, switch) with consistent braces and spacing.
  • Long expressions and argument lists are wrapped at the column limit.

Style presets

clang-format ships with the coding styles of well-known projects:

  • LLVM – 2-space indentation in LLVM itself (configurable here), braces on the same line.
  • Google – Google's style guide; the usual choice for Java and many C++ projects.
  • Chromium and Mozilla – the browsers' variants of the Google and LLVM styles.
  • WebKit – 4-space indentation, function braces on their own line.
  • Microsoft – Allman braces (every brace on its own line), common in C# and Windows code.
  • GNU – the GNU coding standards with half-indented braces.

You can override the indentation (2 or 4 spaces or tabs) and the column limit (80, 100, 120, or no limit) on top of any preset.

The LLVM style with 4-space indentation is selected by default for C, a neutral choice that suits most projects. Choose GNU for GNU projects or Mozilla/WebKit if your code base follows those conventions.

How to use it

  1. Paste C code, open a .c or .h file, or click Sample.
  2. Choose style, indentation, and column limit.
  3. Copy or download the formatted file.

Notes

clang-format reformats tokens; it does not compile or analyse the code, so it works on fragments and on code with missing headers. Short functions may be placed on a single line in some styles (for example int main() { return 0; } in LLVM style) — that is a style decision of the preset.

Format C++ code with the C++ Beautifier, check bit-level logic with the Bitwise Calculator, or convert numbers between bases with the Hex to Decimal converter.

Frequently Asked Questions

There is no built-in kernel preset, but choosing LLVM or GNU with tabs and an 80-column limit gets close. The kernel ships its own .clang-format file for exact results.

Preprocessor lines are kept and code between #ifdef blocks is formatted. Very complex macros may be left largely as written.

Yes. Header files use the same C syntax; paste them or open a .h file.