From 800d0802e41087e52df4af0082c3057e9a8dff94 Mon Sep 17 00:00:00 2001 From: Anita Zhang Date: Tue, 27 Oct 2020 00:16:25 -0700 Subject: [PATCH] docs: update coding style for `return (void) func(...)` Seems that people think it's useful for brevity so make it explicit in the CODING_STYLE. --- docs/CODING_STYLE.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/CODING_STYLE.md b/docs/CODING_STYLE.md index 8f9b2d43b8..851676bc2b 100644 --- a/docs/CODING_STYLE.md +++ b/docs/CODING_STYLE.md @@ -318,6 +318,14 @@ layout: default unlink("/foo/bar/baz"); ``` + When returning from a `void` function, you may also want to shorten the error + path boilerplate by returning a function invocation cast to `(void)` like so: + + ```c + if (condition_not_met) + return (void) log_tests_skipped("Cannot run ..."); + ``` + Don't cast function calls to `(void)` that return no error conditions. Specifically, the various `xyz_unref()` calls that return a `NULL` object shouldn't be cast to `(void)`, since not using the return value