import { _ as _export_sfc, c as createElementBlock, o as openBlock, a8 as createStaticVNode } from "./chunks/framework.Clpp4x2N.js"; const __pageData = JSON.parse('{"title":"Coding Conventions (C)","description":"","frontmatter":{},"headers":[],"relativePath":"coding_conventions_c.md","filePath":"coding_conventions_c.md"}'); const _sfc_main = { name: "coding_conventions_c.md" }; const _hoisted_1 = /* @__PURE__ */ createStaticVNode('

Coding Conventions (C)

Most of our style is pretty easy to pick up on, but right now it's not entirely consistent. You should match the style of the code surrounding your change, but if that code is inconsistent or unclear use the following guidelines:

Here is an example for easy reference:

c
/* Enums for foo */\nenum foo_state {\n    FOO_BAR,\n    FOO_BAZ,\n};\n\n/* Returns a value */\nint foo(void) {\n    if (some_condition) {\n        return FOO_BAR;\n    } else {\n        return -1;\n    }\n}

Auto-formatting with clang-format

Clang-format is part of LLVM and can automatically format your code for you, because ain't nobody got time to do it manually. We supply a configuration file for it that applies most of the coding conventions listed above. It will only change whitespace and newlines, so you will still have to remember to include optional braces yourself.

Use the full LLVM installer to get clang-format on Windows, or use sudo apt install clang-format on Ubuntu.

If you run it from the command-line, pass -style=file as an option and it will automatically find the .clang-format configuration file in the QMK root directory.

If you use VSCode, the standard C/C++ plugin supports clang-format, alternatively there is a separate extension for it.

Some things (like LAYOUT macros) are destroyed by clang-format, so either don't run it on those files, or wrap the sensitive code in // clang-format off and // clang-format on.

', 11); const _hoisted_12 = [ _hoisted_1 ]; function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { return openBlock(), createElementBlock("div", null, _hoisted_12); } const coding_conventions_c = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]); export { __pageData, coding_conventions_c as default };