1- RT-Thread Coding Style
1+ @ page rtt_code_style_en RT-Thread Coding Style
22
33This is an developing instruction for RT-Thread developers. As open source
44software, RT-Thread is created by the cooperation of different people. This
@@ -7,22 +7,22 @@ RT-Thread users should also get to know some conventions in the code through it
77and thus easier to understand the implementations of RT-Thread.
88
99
10- 1 . Directory Naming
10+ # 1. Directory Naming
1111
1212In normal conditions, please name directories in lowercase. Directories should
1313have descriptive names. For example, the port of a chip should be composed of
1414the name of the chip and the category of the chip. Directories under components/
1515should name what the component does.
1616
1717
18- 2 . File Naming
18+ # 2. File Naming
1919
2020In normal conditions, please name files in lowercase. If the file is
2121referencing other places, it can have the original name. To avoid naming
2222collision, do not use general names or the names that are frequently used.
2323
2424
25- 3 . Header Files
25+ # 3. Header Files
2626
2727To avoid include the same header file for multiple times, you need to define a
2828symbol like this:
@@ -36,7 +36,7 @@ The symbol should begin and end with "__" to avoid naming collision. The words
3636of the file name should be connected by "_ ". (This convention is called "snake case".)
3737
3838
39- 4 . Header File Comments
39+ # 4. Header File Comments
4040
4141In every header file, there should be copyright information and Change Log
4242record like this:
@@ -52,7 +52,7 @@ record like this:
5252 * 2006-04-26 Bernard add semaphore APIs
5353 */
5454
55- 5 . Structure Defines
55+ # 5. Structure Defines
5656
5757Please name structures in lowercase and connect words with "_ ". For example:
5858
@@ -76,15 +76,15 @@ example:
7676 typedef struct rt_timer* rt_timer_t;
7777
7878
79- 6 . Macros
79+ # 6. Macros
8080
8181In RT-Thread, please use uppercase names for macro definitions. Words are
8282connected by "_ ". Like:
8383
8484 #define RT_TRUE 1
8585
8686
87- 7 . Function Naming and Declaration
87+ # 7. Function Naming and Declaration
8888
8989Please name functions in lowercase. Separate words with "_ ". The API provided to
9090upper application should be declared in header files. If the function don't have
@@ -93,15 +93,15 @@ parameters, it should be declared as void:
9393 rt_thread_t rt_thread_self(void);
9494
9595
96- 8 . Commenting
96+ # 8. Commenting
9797
9898Please use English to comment. There shouldn't be many comments as the
9999comments should describe what the code does. It should describe complicated
100100algorithms, for example. Comments for statements should be placed before the
101101statements or to the right of them. Any other locations are invalid.
102102
103103
104- 9 . Indent
104+ # 9. Indent
105105
106106Please use TAB or 4 spaces to indent. It's preferred to use 4 spaces. If no
107107other special meanings, the indent should begin right after "{":
@@ -123,7 +123,7 @@ aligned with "switch":
123123"case" is aligned with "switch". The following code block should be indented.
124124
125125
126- 10 . Braces and Spaces
126+ # 10. Braces and Spaces
127127
128128For ease of reading, it is advised that braces should occupy the whole line
129129instead of following other statements. Like:
@@ -160,7 +160,7 @@ operators and the strings. There should be no spaces around(inside) parentheses,
160160This is a bad practice.
161161
162162
163- 11 . trace, log Information
163+ # 11. trace, log Information
164164
165165In RT-Thread, rt_kprintf is a commonly used logging routine. In RT-Thread
166166rt_kprintf is implemented as a polling, non-interrupting string output. It is
@@ -175,14 +175,14 @@ variable or a macro). When logging, it should be easy to understand and easy to
175175determine where the problem is.
176176
177177
178- 12 . Functions
178+ # 12. Functions
179179
180180Functions in kernel should be K.I.S.S. ("Keep it simple, stupid.") If the function
181181is too long, you should split it into smaller ones, with each of them simplified to
182182be easy to understand.
183183
184184
185- 13 . Objects
185+ # 13. Objects
186186
187187The kernel of RT-Thread uses object-oriented techniques in C. The naming convention
188188is: structure names are the object names, object names + verb phrases are the
@@ -211,7 +211,7 @@ When creating a new object, think twice on memory allocations: whether a static
211211object could be created or it could only created dynamically on the heap. Allocations
212212can be slower, but may be necessary in dynamic environments.
213213
214- 14 . Use astyle to format the code automatically
214+ # 14. Use astyle to format the code automatically
215215parameters: --style=allman
216216 --indent=spaces=4
217217 --indent-preproc-block
0 commit comments