From be5ddb8a2c1158f874d96c3c82d2039b30e699be Mon Sep 17 00:00:00 2001 From: Arnau478 Date: Thu, 25 Aug 2022 20:39:02 +0200 Subject: [PATCH] Basic code styling conventions --- STYLE.md | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 STYLE.md diff --git a/STYLE.md b/STYLE.md new file mode 100644 index 0000000..361f2bd --- /dev/null +++ b/STYLE.md @@ -0,0 +1,79 @@ +# Code styling guide + +This document describes the code styling conventions to use for any contribution to this project + +## Global + +Some conventions are applied to all languages (unless otherwise indicated) + - 4 space indentation + - Comments should have a space between the symbol designating it and the comment itself + +## C + +```c +// Pre-processor directives should generally go in the following order: +// 1. #pragma +// 2. #include +// 3. #define + +// Includes with <> should go before includes with "" +#include +#include "vga.h" + +// Pre-processor definitions should be in UPPER_SNAKE_CASE +#define SOME_DEFINE + +// All function and variable names should be in lower_snake_case +int add(int a, int b); + +// Opening curly brackets ('{') should NOT go in a separate line +int add(int a, int b){ + return a + b; +} + +// Asterisks denoting a pointer should be separated from the +// type definition but NOT from the variable/function name +// Examples: +// - char *str <- This is ok +// - char* str <- This is NOT ok +// - char * str <- This is NOT ok +// - char*str <- This is NOT ok +// This also applies to casts: +// - (char *)str <- This is ok +// - (char*)str <- This is NOT ok +void say(char *str){ + printf("You said: %s\n", str); +} + +int main(){ + say("Hello"); + // Switch statement should be as shown below + switch(add(1, 1)){ + case 0: + // ... + break; + case 1: + // ... + break; + case 2: + // ... + break; + default: + // ... + } + + return add(3, 4); +} +``` + +## x86 nasm assembly + +```assembly +; Directives such as "bits 32" should be encapsulated with [] +[bits 32] + +; Everything is written in lowercase +start: + ; Instructions should be 1-level indented + mov eax, ebx +```