`/`*
and *`/`
should be used to start and end comments.
- All comments end with a period.
- Use of `goto` is discouraged.
- Only spaces should be used for indenting. A single indent is 4 spaces. No tab characters should be used.
- A parenthesis is usually followed by a space (see @ref guide_developer_styleguide_codingstyle_example).
- Lines of code should be less than 80 characters long, although longer lines are permitted.
- Local variables should be declared at the top of a block in the narrowest scope possible. Reducing complexity could be a valid case for breaking this guideline, so this should be done at the programmer's discretion.
- All global variables should be declared at the top of a file.
- Variables are always initialized.
- A separator is placed between different sections of a file. The current separator is:
@code{c}
/*-----------------------------------------------------------*/
@endcode
- All files must include the config file at the top of the file before any other includes.
- `static` functions must have a declaration at the top of the file and be implemented before any application-facing functions.
- The [GNU complexity](https://www.gnu.org/software/complexity/manual/complexity.html) of every function should be less than 9.
- Deviations from [MISRA C:2012](https://en.wikipedia.org/wiki/MISRA_C) coding guidelines should be documented as comments in the code.
@subsection guide_developer_styleguide_codingstyle_typeguidelines Type guidelines
@brief Guidelines for variable types.
- Although not a part of the C89 standard, only fixed-width integer types should be used. Exceptions are for `bool` and types required by third-party APIs.
- The default integer in the libraries should be 32 bits wide, i.e. `int32_t` or `uint32_t`.
- Sizes and lengths should be represented with `size_t`.
- Libraries may define `bool` macros for use with C89 compilers.
@section guide_developer_styleguide_codingstyle_example Example File
@brief An example file that follows the coding style rules.
See @ref guide_developer_styleguide_naming for how to name the functions, variables, and macros.
@code{c}
/*
* License header pasted here.
*/
/**
* @file example_file.c
* @brief An example of how source files are typically written in this SDK.
*/
/* Included headers are at the top of the file. The config file include is always first. */
#include "config.h"
/* Standard includes are immediately after the config file. They are sorted alphabetically.
* They use angle brackets <> around the file name. */
/* Standard includes. */
#include File names for demos should begin with `library_demo_`. Unit tests must start with `library_` and end with `_utest`. System tests must start with `library_` and end with `_system_test`. The names should then specify the library being demoed or tested. For example, the files names of the MQTT library's demos start with `mqtt_demo_`. Additionally, test file names should describe what tests are implemented in the file, such as `mqtt_demo_mutual_auth.c` for a file containing a demo that mutually authenticates over TLS with an MQTT broker.
@subsection guide_developer_styleguide_naming_functions Functions (and function-like macros) @brief Naming convention of functions and function-like macros. @formattable{function} @formattableentry{Library`_`Description,Externally-visible library function,`MQTT_Publish`} @formattableentry{description,`static` function (never uses `Aws` prefix),`sendPublish`