From f0d916ae17832df9243cb890fe6a173de20ef891 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 22 Dec 2015 13:39:29 -0800 Subject: Initial style guide --- doc/c-style-guide.md | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 doc/c-style-guide.md 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) -- cgit v1.2.3 From ff298f68884ec48d3bb5f678278c8b21f7a1f31c Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 22 Dec 2015 14:06:44 -0800 Subject: First round of feedback --- doc/c-style-guide.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/doc/c-style-guide.md b/doc/c-style-guide.md index 56132931e2..87de8892dd 100644 --- a/doc/c-style-guide.md +++ b/doc/c-style-guide.md @@ -17,6 +17,19 @@ Header Files ------------ - Public header files (those in the include/grpc tree) should compile as pedantic C89 +- Public header files should be includable from C++ programs. That is, they should + include the following: + ```c + #ifdef __cplusplus + extern "C" { + # endif + + /* ... body of file ... */ + + #ifdef __cplusplus + } + # endif + ``` - 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. @@ -31,6 +44,17 @@ C99 Features - Variable sized arrays are not allowed - Do not use the 'inline' keyword +- Flexible array members are allowed (https://en.wikipedia.org/wiki/Flexible_array_member) + +Comments +-------- + +Within public header files, only `/* */` comments are allowed. + +Within implementation files and private headers, either single line `//` +or multi line `/* */` comments are allowed. Only one comment style per file is +allowed however (i.e. if single line comments are used anywhere within a file, +ALL comments within that file must be single line comments). Symbol Names ------------ -- cgit v1.2.3