This article is a coding style summarized by myself, used to standardize my code, enhance readability, and non-standard specifications. Forcing yourself to form a good coding style is conducive to the development of large-scale programs without being cluttered. Refer to STM32 firmware library coding style and FreeRTOS coding style.
- Modify the code of the third party or open source community, follow the original code style and the relevant conventions of the community
- C/C++ brand new code follows WebKit style
- Before each commit, run clang-format(
sudo apt install clang-format
) again , the following command will directly modify the source file:
clang-format --style=WebKit -i filetocheck
- Or through VSCode:
- Pure C code naming convention:
- File names/variables/constant names are all lowercase, and words are separated by underscore "_"
- #define Macro definitions are all uppercase
- Enumeration constants are all uppercase
- The structure/enumeration type definition ends with _t, such as mible_packet_t.
- Header file #define protection
- All header files should use #define to prevent header files from being included multiple times. The naming format should be:
<PROJECT>_<PATH>_<FILE>_H_
- The path and order of include (remember not to use relative paths):
- The .h file corresponding to the source file (put at the top to avoid implicit include by the compiler)
- C system files
- C++ system files
- .H files of other libraries
- .H file in this project