This style guide is meant to be loosely adhered to when writing libraries for the Wonderful ecosystem.
Note that this is very much a draft - I'm trying to codify what I learned from the past few years… please remain patient.
As everyone downstream will end up using the hardware libraries' API, consistency in naming is among the most important things to pay attention to. Formatting can be fixed for free; naming changes are expensive.
Regarding cases:
snake_case
. This allows easily distinguishing them from function names in more modern languages on top of the C API, which tend to use PascalCase
or camelCase
.UPPER_SNAKE_CASE
.static inline
function and a macro can sometimes be very thin.Regarding names:
libws
, a global function name should be ws_function(void)
, not function(void)
.libwsx
, the name is wsx_function(void)
; even if it also targets the ws
platform, the library is different, so the prefix changes likewise.ws_screen_fill_tiles
is appropriate, not ws_screen_tiles_fill
or ws_fill_screen_tiles
.is
.ws_system_is_color_active
, not ws_system_color_active
.WS_DISPLAY_BORDER_PORT
, and a mask for WS_DISPLAY_BORDER_COLOR(c)
will be referred to as WS_DISPLAY_BORDER_COLOR_MASK
.
void braces_on_the_same_line(int always) {
if (single_line)
no_braces_is_fine;
if (multi_line) {
braces_on_the_same_line(1);
braces_on_the_same_line(2);
}
}
*
adjacent to the type name. const
goes before the type name.
const void __far *return_pointer(void __far *my_pointer);
Use Doxygen-compatible formatting for all user-facing documentation comments:
/** .. */
blocks for documenting functions, types, macros and/or where larger comment blocks are warranted;///<
can be used./// @cond INTERNAL
and /// @endcond
blocks.stdint.h
and stdbool.h
types (int16_t
, uint32_t
etc). Where the size of a variable doesn't matter, use standard C types (int
and unsigned int
).stdint.h
types more often; int
tends to be 16-bit on those platforms, which is slower to process than uint8_t
.bool
. For functions which return an error code, use int
and return a non-negative value on success or a negative value on failure.static inline
functions over preprocessor macros, where applicable.gnu11
.wswan/medium
), and LTO is not available; as such, using static inline
functions in header files for simple port I/O wrappers and similar tasks is encouraged.