From 602e8dcb999b1129da4887e450bf2d4e09ecb6fe Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Exp=C3=B3sito?= Date: Wed, 2 Mar 2022 08:48:03 +0100 Subject: [PATCH] coding style: allow C99 variable declaration MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Allow to declare variables before they are used in new written code. Signed-off-by: José Expósito --- CODING_STYLE.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/CODING_STYLE.md b/CODING_STYLE.md index 02e5844..cc7bdc2 100644 --- a/CODING_STYLE.md +++ b/CODING_STYLE.md @@ -52,26 +52,28 @@ somenamethatiswaytoolong(int a, - if it generates a static checker warning, it needs to be fixed or commented -- declare variables at the top, try to keep them as local as possible. +- declare variables before they are used, try to keep them as local as possible. Exception: if the same variable is re-used in multiple blocks, declare it at the top. Exception: basic loop variables, e.g. for (int i = 0; ...) ```c int a; -int c; if (foo) { int b; - c = get_value(); - usevalue(c); + a = get_value(); + usevalue(a); } if (bar) { - c = get_value(); - useit(c); + a = get_value(); + useit(a); } + +int c = a * 100; +useit(c); ``` - do not mix function invocations and variable definitions. -- 2.7.4