You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Indentation - four spaces. Please do not use tabs.
74
-
75
74
- Braces - K&R style.
76
-
77
75
- One true brace style (1TBS) - use braces for statements of type `if`, `else`, `while` and `for` (exception [from K&R](http://en.wikipedia.org/wiki/Indent_style#Variant:_1TBS)).
78
-
79
76
- One line per statement.
80
-
81
77
- Preprocessor macro starts at the beginning of a new line; the code inside is indented according to the code above it.
82
-
83
78
- Cases within `switch` are indented (exception from K&R).
84
-
85
79
- Space after statements of type `if`, `while`, `for`, `switch`. The same applies to binary operators (like, `+` and `*`) and the ternary operator (`?` and `:`).
86
-
87
80
- Each line preferably has at most 120 characters.
88
-
89
81
- Comments should use proper spelling and grammar.
90
-
91
82
- For pointers or references, the symbols `*` or `&` are adjacent to a name (`analogin_t *obj`. `analogin_t &obj`). If you omit the name, place the space between the type and `*` (such as `int *` or `int &`).
92
-
93
83
- For function return pointers or references, the symbols `*` or `&` are adjacent to a function name (`int *func()` or `int &func()`).
94
-
95
84
- Don't leave trailing spaces at the end of lines.
96
-
97
85
- Empty lines should have no trailing spaces.
98
-
99
86
- Unix line endings are default option for files.
100
-
101
87
- Use capital letters for macros.
102
-
103
88
- A file should have an empty line at the end.
104
89
105
90
### Naming conventions
106
91
107
92
#### Classes
108
93
109
94
- Begin with a capital letter, and each word within a class also begins with a capital letter (AnalogIn, BusInOut).
110
-
111
95
- Methods contain small letters, with words separated by underscore.
112
-
113
96
- Private members start with an underscore: ``__User defined types (typedef)))``.
114
-
115
97
- Structures - `suffix _t` - to denote it is a user-defined type.
116
-
117
98
- Enumeration - the type name and values name - same naming convention as classes (for example MyNewEnum).
118
99
119
100
#### Functions
120
101
121
102
- Contain lower case letters (as methods within classes).
122
-
123
103
- Words separated by underscore (wait_ms, read_u16).
124
104
125
105
An example:
@@ -163,6 +143,21 @@ struct analogin_s {
163
143
typedef struct analogin_s analogin_t;
164
144
```
165
145
146
+
#### Namespaces
147
+
148
+
Namespaces used to group subsystems are lower case, such as `rtos` and `event`. If not in a specific subsystem, C++ APIs are in namespace `mbed`. A few APIs remain in the global namespace for backward compatibility.
149
+
150
+
Occasionally, namespaces are used to act as-if "static singleton" objects. One example is namespace `ThisThread` in `rtos` (which was modeled after C++11 `std::this_thread`). These namespaces follow the class naming convention, so calls to their functions look like calls to static class methods.
151
+
152
+
Below is an example of typical namespace use in a source file:
153
+
154
+
```
155
+
using namespace rtos;
156
+
157
+
ThisThread::sleep_for(1000);
158
+
159
+
```
160
+
166
161
### Doxygen documentation
167
162
168
163
All functions and methods should contain documentation using Doxygen.
0 commit comments