This documentation guide applies to any code being written in C/C++ on the team.
Variable and function names should be descriptive enough to understand even without comments, but if comments are needed to explain parts of the code, use single line comments with the /* */
notation for better compatibility with old compilers in C.
/* Single line comment */
// Do not use this for C code
Function comments should exist in both the .h and .c files optimally, but at minimum they should be available in the .h files. Comments should follow the format shown below:
/**
* @brief Adds two numbers together
*
* @param num1 - The first number to add.
* @param num2 - The second number to add.
* @return uint8_t - Returns the sum of of the two numbers.
*/
uint8_t add_numbers(uint8_t num1, uint8_t num2);
variableNames
in camelCasefunction_names()
in snake_caseClassNames
in PascalCase (UpperCamelCase)CONSTANT_NAMES
in CAPITAL_SNAKE_CASEfile_names
in snake_caseif ()
and while ()
), but not for function calls (i.e. my_func()
).*
, /
, %
, !
=
, ==
, +
, -
, +=
, -=
, etcmy_func(var1, var2, var3)