qmk_firmware/assets/coding_conventions_c.md.DdrpXBEh.js

16 lines
7.3 KiB
JavaScript
Raw Normal View History

import { _ as _export_sfc, c as createElementBlock, o as openBlock, a8 as createStaticVNode } from "./chunks/framework.DyMmIvSC.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('<h1 id="coding-conventions-c" tabindex="-1">Coding Conventions (C) <a class="header-anchor" href="#coding-conventions-c" aria-label="Permalink to &quot;Coding Conventions (C)&quot;"></a></h1><p>Most of our style is pretty easy to pick up on, but right now it&#39;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:</p><ul><li>We indent using four (4) spaces (soft tabs)</li><li>We use a modified One True Brace Style <ul><li>Opening Brace: At the end of the same line as the statement that opens the block</li><li>Closing Brace: Lined up with the first character of the statement that opens the block</li><li>Else If: Place the closing brace at the beginning of the line and the next opening brace at the end of the same line.</li><li>Optional Braces: Always include optional braces. <ul><li>Good: <code>if (condition) { return false; }</code></li><li>Bad: <code>if (condition) return false;</code></li></ul></li></ul></li><li>We encourage use of C style comments: <code>/* */</code><ul><li>Think of them as a story describing the feature</li><li>Use them liberally to explain why particular decisions were made.</li><li>Do not write obvious comments</li><li>If you&#39;re not sure if a comment is obvious, go ahead and include it.</li></ul></li><li>In general we don&#39;t wrap lines, they can be as long as needed. If you do choose to wrap lines please do not wrap any wider than 76 columns.</li><li>We use <code>#pragma once</code> at the start of header files rather than old-style include guards (<code>#ifndef THIS_FILE_H</code>, <code>#define THIS_FILE_H</code>, ..., <code>#endif</code>)</li><li>We accept both forms of preprocessor if&#39;s: <code>#ifdef DEFINED</code> and <code>#if defined(DEFINED)</code><ul><li>If you are not sure which to prefer use the <code>#if defined(DEFINED)</code> form.</li><li>Do not change existing code from one style to the other, except when moving to a multiple condition <code>#if</code>.</li></ul></li><li>When deciding how (or if) to indent preprocessor directives, keep these points in mind: <ul><li>Readability is more important than consistency.</li><li>Follow the file&#39;s existing style. If the file is mixed, follow the style that makes sense for the section you are modifying.</li><li>When indenting, keep the hash at the start of the line and add whitespace between <code>#</code> and <code>if</code>, starting with 4 spaces after the <code>#</code>.</li><li>You can follow the indentation level of the surrounding C code, or preprocessor directives can have their own indentation levels. Choose the style that best communicates the intent of your code.</li></ul></li></ul><p>Here is an example for easy reference:</p><div class="language-c vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">/* Enums for foo */</span></span>\n<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">enum</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> foo_state {</span></span>\n<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> FOO_BAR,</span></span>\n<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;"> FOO_BAZ,</span></span>\n<span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">};</span></span>\n<span class="line"></span>\n<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">/* Returns a value */</span></span>\n<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">int</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> foo</span><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">(</span><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">void</span><span style="--shiki-light:#24292E;--s
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
};