|
|
<table style="border-collapse: collapse; border: none;">
|
|
|
<tr style="border-collapse: collapse; border: none;">
|
|
|
<td style="border-collapse: collapse; border: none;">
|
|
|
<a href="http://www.openairinterface.org/">
|
|
|
<img src="../images/oai_final_logo.png" alt="" border=3 height=50 width=150>
|
|
|
</img>
|
|
|
</a>
|
|
|
</td>
|
|
|
<td style="border-collapse: collapse; border: none; vertical-align: center;">
|
|
|
<b><font size = "5">Braces and Spaces</font></b>
|
|
|
</td>
|
|
|
</tr>
|
|
|
</table>
|
|
|
|
|
|
# 1. Braces #
|
|
|
|
|
|
The following brace placement is recommended:
|
|
|
|
|
|
```c
|
|
|
if (condition) {
|
|
|
} else if (condition) {
|
|
|
} else {
|
|
|
}
|
|
|
|
|
|
while (condition) {
|
|
|
...
|
|
|
}
|
|
|
|
|
|
switch (a) {
|
|
|
case ‘c’:
|
|
|
break;
|
|
|
…
|
|
|
default:
|
|
|
…;
|
|
|
}
|
|
|
|
|
|
typedef struct my_struct_s {
|
|
|
…
|
|
|
} my_struct_t;
|
|
|
```
|
|
|
|
|
|
## 1.1 Braces and Comments ##
|
|
|
|
|
|
Adding a comment to closing braces can help when you are reading code because you don't have to find the begin brace to know what is going on.
|
|
|
|
|
|
```c
|
|
|
while(1) {
|
|
|
if (valid) {
|
|
|
|
|
|
} /* if valid */
|
|
|
else {
|
|
|
} /* not valid */
|
|
|
|
|
|
} /* end forever */
|
|
|
```
|
|
|
|