1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-25 17:25:20 +03:00

Markdown fixes and added style examples

This commit is contained in:
Tim Eckel 2018-08-28 10:30:55 -04:00 committed by GitHub
parent 9ef901f251
commit 290cfebd99
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -28,14 +28,63 @@ Note2: The Astyle settings have been tested and will produce a nice result. Many
## Curly Braces
Functions shall have the opening brace at the beginning of the next line.
```
int function(int x)
{
body of function
}
```
All non-function statement blocks (if, switch, for) shall have the opening brace last on the same line, with the following statement on the next line.
Closing braces shall be but on the line after the last statement in the block.
```
if (x is true) {
we do y
...
}
```
```
switch (action) {
case ADD:
return "add";
case REMOVE:
return "remove";
case CHANGE:
return "change";
default:
return NULL;
}
```
If it is followed by an `else` or `else if` that shall be on the same line, again with the opening brace on the same line.
```
if (x is true) {
we do y
...
} else {
we do z
...
}
```
A single statement after an `if` or an `else` may omit the "unnecessary" braces only when ALL conditional branches have single statements AND you have strong reason to know it will always be that way.
```
if (x is true)
we do y
else
we do z
```
```
if (x is true) {
we do y
...
} else {
we do z
}
```
If in doubt, do not omit such "unnecessary" braces.
(Adding a statement to a branch will break the logic if the braces are forgotten and otherwise make the PR longer).