aboutsummaryrefslogtreecommitdiff
path: root/C/README.md
diff options
context:
space:
mode:
authorOxbian <oxbian@mailbox.org>2024-10-13 14:39:12 -0400
committerOxbian <oxbian@mailbox.org>2024-10-13 14:39:12 -0400
commitece2583cee34ad19e3b3458e9c884638c8f8b73c (patch)
tree95fdf495026996f0e7df91edd11bed1cf134e549 /C/README.md
parent70a6c7e47e65893f5522040d51ab1d3651a5599f (diff)
downloadcoding-style-ece2583cee34ad19e3b3458e9c884638c8f8b73c.tar.gz
coding-style-ece2583cee34ad19e3b3458e9c884638c8f8b73c.zip
feat: ArKa C coding style
Diffstat (limited to 'C/README.md')
-rw-r--r--C/README.md77
1 files changed, 77 insertions, 0 deletions
diff --git a/C/README.md b/C/README.md
new file mode 100644
index 0000000..0cd1d57
--- /dev/null
+++ b/C/README.md
@@ -0,0 +1,77 @@
+# C ArKa Coding style
+---
+
+The coding style used for C project by ArKa, is the same used in the Linux Kernel.
+
+## File layout
+
+Files MUST follow this layout:
+- Comment with LICENSE and short explaination of the file / tool
+- Headers
+- Macros
+- Types
+- Function declarations:
+ - Include variable names.
+ - For short files these can be left out.
+ - Group/order in logical manner.
+- Global variables.
+- Function definitions in same order as declarations.
+- main (if needed)
+
+## Compilation & Makefile
+
+To compile C code, a magical tool was created, Makefiles.
+
+Makefiles MUST look likes Makefile from [Makefile tutor](https://clemedon.github.io/Makefile_tutor/)
+
+Every project should be compiled with those flags:
+`-O2 -Wall -Wformat -Wformat=2 -Wconversion -Wimplicit-fallthrough \
+-Werror=format-security \
+-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 \
+-D_GLIBCXX_ASSERTIONS \
+-fstrict-flex-arrays=3 \
+-fstack-clash-protection -fstack-protector-strong \
+-Wl,-z,nodlopen -Wl,-z,noexecstack \
+-Wl,-z,relro -Wl,-z,now \
+-Wl,--as-needed -Wl,--no-copy-dt-needed-entries`
+
+For test/debug, use those flags:
+`-fsanitize=address -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize=leak -fno-omit-frame-pointer -fsanitize=undefined -fsanitize=bounds-strict -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow
+export ASAN_OPTIONS=strict_string_checks=1:detect_stack_use_after_return=1:check_initialization_order=1:strict_init_order=1:detect_invalid_pointer_pairs=2`
+
+List of flags every project should use [by FSF](https://best.openssf.org/Compiler-Hardening-Guides/Compiler-Options-Hardening-Guide-for-C-and-C++.html)
+
+List of flags every project should use [by Airbus security](https://airbus-seclab.github.io/c-compiler-security/)
+
+Explaination of every flags with [this stackexchange post](https://security.stackexchange.com/questions/24444/what-is-the-most-hardened-set-of-options-for-gcc-compiling-c-c)
+
+
+## Code style
+
+You can use the configured clang-format file to automatically format your code.
+
+## Project setup
+
+The project tree sould basically look like this:
+
+```
+my_project/
+|--- .git/
+|--- src/
+| |----- main.c
+|--- include/
+| |---- main.h
+|--- Makefile
+|--- README.md
+|--- .clang-format
+```
+
+Because we are not using some autocompilations tools, clang doesn't know the
+structure of the project. To help him understand it, we need to make the
+Makefile in first, and use bear for helping clang to understand the project.
+
+So once the Makefile is made, just run `make all; bear -- make`
+
+## Folder and filename
+
+Folder name MUST start with an uppercase, and filename
ArKa projects. All rights to me, and your next child right arm.