1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-24 08:45:36 +03:00

Merge pull request #10505 from dellch/feature/cleanup-coding-style-braces-section

This commit is contained in:
Michael Keller 2021-01-24 16:52:12 +13:00 committed by GitHub
commit 816819d3d9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -30,17 +30,20 @@ Sometimes, for example, you may want other columns and line breaks so it looks l
Note2: The Astyle settings have been tested and will produce a nice result. Many files will be changed, mostly to the better but maybe not always, so use with care.
## Curly Braces
Functions shall have the opening brace at the beginning of the next line.
### Functions
Functions shall have the opening and closing braces at the beginning of the next line, and followed by a line break.
```
int function(int x)
{
body of function
}
```
### Non-function statement blocks
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.
#### Opening braces
All non-function statement blocks (i.e. `if`, ` switch`, `for`, as well as any others) shall have the opening brace last on the same line, with the following statement on the next line.
#### Closing braces
Closing braces shall be but on the line after the last statement in the block.
```
if (x is true) {
@ -62,7 +65,7 @@ default:
}
```
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 the closing brace 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
@ -72,7 +75,7 @@ if (x is true) {
...
}
```
###Braces are required
Omission of "unnecessary" braces in cases where an `if` or `else` block consists only of a single statement is not permissible in any case. These "single statement blocks" are future bugs waiting to happen when more statements are added without enclosing the block in braces.
## Spaces