design:coding_style_guide
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
design:coding_style_guide [2025/05/04 07:16] – asie | design:coding_style_guide [2025/05/05 15:17] (current) – [Commenting] asie | ||
---|---|---|---|
Line 24: | Line 24: | ||
* Following from that, categorizing functions should be done prefix-first, | * Following from that, categorizing functions should be done prefix-first, | ||
* For example, '' | * For example, '' | ||
+ | * Predicate functions should use the verb '' | ||
+ | * For example, '' | ||
* Some macros can refer to a type; for readability and to distinguish it from function categories, these should be // | * Some macros can refer to a type; for readability and to distinguish it from function categories, these should be // | ||
- | * For example, an I/O port will be referred to as '' | + | * For example, an I/O port will be referred to as '' |
- | ===== Code formatting | + | ===== Code style ===== |
+ | |||
+ | * Braces are always on the same line, and are separated with a space. | ||
+ | * If it doesn' | ||
<code c> | <code c> | ||
Line 36: | Line 41: | ||
if (multi_line) { | if (multi_line) { | ||
braces_on_the_same_line(1); | braces_on_the_same_line(1); | ||
- | | + | |
- | // ... but treat sizeof, etc. like a function. | + | |
- | memcpy(&b, &a, sizeof(a)); | + | |
} | } | ||
} | } | ||
</ | </ | ||
- | ===== Commenting | + | * Pointers are declared with the asterisk '' |
+ | |||
+ | <code c> | ||
+ | const void __far *return_pointer(void __far *my_pointer); | ||
+ | </ | ||
+ | |||
+ | ===== Documentation | ||
Use [[https:// | Use [[https:// | ||
- | * Javadoc-style ''/ | + | * Javadoc-style '' |
* For one-line comments, such as on enumerated types, '' | * For one-line comments, such as on enumerated types, '' | ||
+ | * When writing internal header macros/ | ||
+ | ===== Best practices ===== | ||
- | ===== Standards adherence ===== | + | * Where the size of a variable matters, use '' |
+ | * For 8-bit platforms, rely on '' | ||
+ | * For functions which return a " | ||
+ | * Prefer '' | ||
- | For target code on most platforms, it is acceptable to depend on a feature even if it is only available in modern versions of GCC **and** Clang. | + | ===== Target-specific notes ===== |
- | Special consideration may need to be taken for platforms where the GNU/LLVM compiler is not necessarily the best open source option, such as the 8086, SM83 or Z80. | + | ==== wswan ==== |
- | ===== Best practices ===== | + | |
- | + | * The cost of a function call is rather high (5 bytes and 18 cycles of overhead for argument-less functions | |
- | | + | |
- | * For 8-bit platforms, rely on these more often; | + | |
- | * For functions which return a " | + | |
====== References ====== | ====== References ====== | ||
* [[https:// | * [[https:// |
design/coding_style_guide.1746343001.txt.gz · Last modified: 2025/05/04 07:16 by asie