aboutsummaryrefslogtreecommitdiffhomepage
path: root/doc/c-style-guide.md
diff options
context:
space:
mode:
authorGravatar Craig Tiller <ctiller@google.com>2015-12-22 13:39:29 -0800
committerGravatar Craig Tiller <ctiller@google.com>2015-12-22 13:40:30 -0800
commitf0d916ae17832df9243cb890fe6a173de20ef891 (patch)
tree5edd33f217a51650d7764827bdaa97c96b8a9358 /doc/c-style-guide.md
parent2dd2e895d9c783f7247bbe70be692118f964532b (diff)
Initial style guide
Diffstat (limited to 'doc/c-style-guide.md')
-rw-r--r--doc/c-style-guide.md41
1 files changed, 41 insertions, 0 deletions
diff --git a/doc/c-style-guide.md b/doc/c-style-guide.md
new file mode 100644
index 0000000000..56132931e2
--- /dev/null
+++ b/doc/c-style-guide.md
@@ -0,0 +1,41 @@
+GRPC C STYLE GUIDE
+=====================
+
+Background
+----------
+
+Here we document style rules for C usage in the gRPC Core library.
+
+General
+-------
+
+- Layout rules are defined by clang-format, and all code should be passed through
+ clang-format. A (docker-based) script to do so is included in
+ tools/distrib/clang_format_code.sh.
+
+Header Files
+------------
+
+- Public header files (those in the include/grpc tree) should compile as pedantic C89
+- Header files should be self-contained and end in .h.
+- All header files should have a #define guard to prevent multiple inclusion.
+ To guarantee uniqueness they should be based on the file's path.
+
+ For public headers: include/grpc/grpc.h --> GRPC_GRPC_H
+
+ For private headers:
+ src/core/channel/channel_stack.h --> GRPC_INTERNAL_CORE_CHANNEL_CHANNEL_STACK_H
+
+C99 Features
+------------
+
+- Variable sized arrays are not allowed
+- Do not use the 'inline' keyword
+
+Symbol Names
+------------
+
+- Non-static functions must be prefixed by grpc_
+- static functions must not be prefixed by grpc_
+- enumeration values and #define names are uppercased, all others are lowercased
+- Multiple word identifiers use underscore as a delimiter (NEVER camel casing)