mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2026-01-10 03:20:15 +01:00
coding style: allow C99 variable declaration
Allow to declare variables before they are used in new written code. Signed-off-by: José Expósito <jose.exposito89@gmail.com>
This commit is contained in:
parent
5664007013
commit
602e8dcb99
1 changed files with 8 additions and 6 deletions
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue