summaryrefslogtreecommitdiffstats
path: root/doc
diff options
context:
space:
mode:
authorSharvil Nanavati <sharvil@google.com>2015-04-07 22:45:21 -0700
committerSharvil Nanavati <sharvil@google.com>2015-04-07 22:50:03 -0700
commit1b80439e3d7c6f89c0952fd0bb8227a0197c8583 (patch)
treec8b6074a57007d7253b2059ba4a3f81b29c37faf /doc
parentf29a2fb0940a90a2c4dd3aebe998557b31aaa29e (diff)
downloadandroid_system_bt-1b80439e3d7c6f89c0952fd0bb8227a0197c8583.tar.gz
android_system_bt-1b80439e3d7c6f89c0952fd0bb8227a0197c8583.tar.bz2
android_system_bt-1b80439e3d7c6f89c0952fd0bb8227a0197c8583.zip
Add a section to the style guide on variable declarations.
Change-Id: I0eaa435378b56953c1c228c795d0b4bf9bd8ce6c
Diffstat (limited to 'doc')
-rw-r--r--doc/style_guide.md24
1 files changed, 24 insertions, 0 deletions
diff --git a/doc/style_guide.md b/doc/style_guide.md
index 7f38e8480..b0e6835b7 100644
--- a/doc/style_guide.md
+++ b/doc/style_guide.md
@@ -87,6 +87,30 @@ void function(void);
Note that the function explicitly includes `void` in its parameter list to
indicate to the compiler that it takes no arguments.
+### Variable declarations
+Variables should be declared one per line as close to initialization as possible.
+In nearly all cases, variables should be declared and initialized on the same line.
+Variable declarations should not include extra whitespace to line up fields. For
+example, the following style is preferred:
+```
+ int my_long_variable_name = 0;
+ int x = 5;
+```
+whereas this code is not acceptable:
+```
+ int my_long_variable_name = 0;
+ int x = 5;
+```
+
+As a result of the above rule to declare and initialize variables together,
+`for` loops should declare and initialize their iterator variable in the
+initializer statement:
+```
+ for (int i = 0; i < 10; ++i) {
+ // use i
+ }
+```
+
### Contiguous memory structs
Use C99 flexible arrays as the last member of a struct if the array needs
to be allocated in contiguous memory with its containing struct.