From eb5b360d72eb312221b36746afeb786e39b5e40e Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Tue, 14 Jan 2020 12:31:27 -0500 Subject: [PATCH] Add a few more guidelines based on Linux style --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index 61be427..6b25edf 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ Send questions and feedback to - [Features to avoid](#features-to-avoid) - [Brace placement](#brace-placement) - [Function declarations](#function-declarations) +- [goto](#goto) - [Header files](#header-files) - [Space placement](#space-placement) - [Splitting long lines](#splitting-long-lines) @@ -122,6 +123,10 @@ Programmers **SHOULD prefer to stack-allocate resources.** - You MAY pass pointers to your stack resources to functions, but you MUST ensure that those pointers do not outlive their stack frame. +Programmers **SHOULD prefer calloc for heap-allocated resources.** + +- It automatically zeroes out the memory so you can't forget to. + ## Features to avoid Programmers **SHOULD NOT use language extensions**, such as gcc-specific features. @@ -378,6 +383,14 @@ int my_function(parameters...); - This excludes prototypes from the grep example shown in the previous rule. +## goto + +Programmers **SHOULD use goto to deduplicate error handling.** + +- If your function has many error cases and has to clean up any resources before + exiting in an error condition, you should have an error: label and goto to it + to perform this cleanup. + ## Header files Programmers **MUST add include guards.** -- 2.45.2