Update 'Coding Style'
parent
ab274a4a22
commit
116fb27c49
1 changed files with 54 additions and 0 deletions
|
@ -99,6 +99,60 @@ exit(error);
|
|||
```
|
||||
|
||||
### Braces
|
||||
|
||||
Curly braces for function definitions should rest on a new line and should not add an indentation level:
|
||||
|
||||
```c
|
||||
uint64
|
||||
bytes_used(bwc_stream const *const stream)
|
||||
{
|
||||
if(stream->T == 0xFF)
|
||||
return stream->L + 1;
|
||||
else
|
||||
return stream->L;
|
||||
}
|
||||
```
|
||||
|
||||
A new block should always be placed on a new indentation level:
|
||||
```c
|
||||
f = fopen('file');
|
||||
{
|
||||
if(stream->T == 0xFF)
|
||||
return stream->L + 1;
|
||||
else
|
||||
return stream->L;
|
||||
}
|
||||
fclose(f);
|
||||
```
|
||||
|
||||
Curly braces should not be used for single statement blocks
|
||||
|
||||
```c
|
||||
if(stream->T == 0xFF)
|
||||
return stream->L + 1;
|
||||
else
|
||||
return stream->L;
|
||||
```
|
||||
unless one of the following 4 exceptions applies:
|
||||
|
||||
1. If either side of an if…else statement has braces
|
||||
```c
|
||||
if(stream->T == 0xFF)
|
||||
return stream->L + 1;
|
||||
else
|
||||
return stream->L;
|
||||
```
|
||||
2. If a single statement covers multiple lines
|
||||
```c
|
||||
```
|
||||
3. If the condition is composed of many lines
|
||||
```c
|
||||
```
|
||||
4. Nested if, in which case the block should be placed on the outermost if
|
||||
```c
|
||||
```
|
||||
|
||||
|
||||
### Whitespace
|
||||
|
||||
```c
|
||||
|
|
Loading…
Reference in a new issue