mirror of
https://github.com/labwc/labwc.git
synced 2025-10-31 22:25:34 -04:00
CONTRIBUTING.md: document use of braces in switch statements
This commit is contained in:
parent
68bf55d724
commit
8ff779ca25
1 changed files with 26 additions and 0 deletions
|
|
@ -324,6 +324,32 @@ We use the prefix `handle_` for signal-handler-functions in order to be
|
||||||
consistent with sway and rootston. For example
|
consistent with sway and rootston. For example
|
||||||
`view->request_resize.notify = handle_request_resize`
|
`view->request_resize.notify = handle_request_resize`
|
||||||
|
|
||||||
|
### Switch statements with variable declarations
|
||||||
|
|
||||||
|
Unlike many modern languages, C doesn't create a new scope after `case FOO:`.
|
||||||
|
Therefore, we wrap codes following `case FOO:` that include variable
|
||||||
|
declarations with braces (`{..}`) to reduce variable scopes. For example:
|
||||||
|
|
||||||
|
```
|
||||||
|
switch (x) {
|
||||||
|
case FOO: {
|
||||||
|
int y = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case BAR: {
|
||||||
|
do_something();
|
||||||
|
int z = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case BAZ:
|
||||||
|
do_something();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
But please also consider refactoring the code into a separate function if it
|
||||||
|
becomes lengthy.
|
||||||
|
|
||||||
# Commit Messages
|
# Commit Messages
|
||||||
|
|
||||||
The log messages that explain changes are just as important as the changes
|
The log messages that explain changes are just as important as the changes
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue