Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
platform_packages_modules_Bluetooth
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LMODroid
platform_packages_modules_Bluetooth
Commits
61243816
Commit
61243816
authored
10 years ago
by
Sharvil Nanavati
Committed by
Andre Eisenbach
10 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Code formatting and language feature additions to the style guide.
parent
8efa754c
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
system/doc/style_guide.md
+80
-0
80 additions, 0 deletions
system/doc/style_guide.md
with
80 additions
and
0 deletions
system/doc/style_guide.md
+
80
−
0
View file @
61243816
...
...
@@ -79,6 +79,14 @@ Variadic functions are dangerous and should be avoided for most code. The
exception is when implementing logging since the benefits of readability
outweigh the cost of safety.
### Functions with zero arguments
Functions that do not take any arguments (0 arity) should be declared like so:
```
void function(void);
```
Note that the function explicitly includes
`void`
in its parameter list to
indicate to the compiler that it takes no arguments.
### Zero-length arrays
Use zero-length arrays as the last member of a struct if the array needs to be
allocated in contiguous memory with its containing struct. For example:
...
...
@@ -109,6 +117,11 @@ uint8_t *data = (uint8_t *)(my_buffer + 1);
Instead, use zero-length arrays as described above to avoid pointer arithmetic
and array indexing entirely.
### Boolean type
Use the C99
`bool`
type with values
`true`
and
`false`
defined in
`stdbool.h`
.
Not only is this a standardized type, it is also safer and provides more
compile-time checks.
## Header files
In general, every source file (
`.c`
or
`.cpp`
) in a
`src/`
directory should
have a corresponding header (
`.h`
) in the
`include/`
directory.
...
...
@@ -172,3 +185,70 @@ After the license header, each header file must contain the include guard:
This form is used over traditional
`#define`
-based include guards as it is less
error-prone, doesn't pollute the global namespace, is more compact, and can
result in faster compilation.
## Formatting
Code formatting is pretty arbitrary, but the codebase is easier to follow if
everyone uses the same style. Individuals may not agree with every aspect of
the formatting rules, and some of the rules may take some getting used to,
but it is important that all engineers follow the formatting rules so we can all
understand and read the code easily.
### White space
*
use only spaces, indent 2 spaces at a time
*
no trailing whitespaces at the end of a line
*
no tab characters
*
use one blank line to separate logical code blocks, function definitions,
and sections of a file
```
// Space after keyword in conditionals and loops.
// No space immeidately before or after parentheses.
if (foo)
// Space surrounding binary operators.
if (foo < 5)
// Space after comma.
for (int x = 0, y = 0; x; ++y)
// No space between unary operators and their argument.
++x;
z = -y;
// No space between function name and open parenthesis.
call_my_fn(arg1, arg2);
// Space before * in variable declaration.
int *x = NULL;
// Space after // beginning a comment.
// Notice the space between "//" and "N".
```
Use only spaces, and indent 2 spaces at a time. Do not use tab characters in the
codebase.
Use a single blank line to separate logical code blocks, function definitions,
and sections of a file.
### Brace style
```
// Open curly braces are never on a line by themselves.
void my_function(void) {
// Conditional statements with only one child statement should elide braces.
// The child statement must be on a new line, indented by 2 spaces.
if (foo)
do_bar();
else
do_baz();
// Conditionals with a branch containing more than one child statement forces
// braces on both branches.
if (foo) {
do_bar();
} else {
do_baz();
++var1;
}
}
```
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment