From 116fb27c495c105bc8f1c5845c6fecab08177d98 Mon Sep 17 00:00:00 2001 From: Patrick Vogler Date: Wed, 21 Jun 2023 16:37:13 +0000 Subject: [PATCH] Update 'Coding Style' --- Coding-Style.md | 54 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/Coding-Style.md b/Coding-Style.md index 938bbe7..5e38400 100644 --- a/Coding-Style.md +++ b/Coding-Style.md @@ -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