OLD | NEW |
(Empty) | |
| 1 GRPC C STYLE GUIDE |
| 2 ===================== |
| 3 |
| 4 Background |
| 5 ---------- |
| 6 |
| 7 Here we document style rules for C usage in the gRPC Core library. |
| 8 |
| 9 General |
| 10 ------- |
| 11 |
| 12 - Layout rules are defined by clang-format, and all code should be passed throug
h |
| 13 clang-format. A (docker-based) script to do so is included in |
| 14 tools/distrib/clang_format_code.sh. |
| 15 |
| 16 Header Files |
| 17 ------------ |
| 18 |
| 19 - Public header files (those in the include/grpc tree) should compile as pedanti
c C89 |
| 20 - Public header files should be includable from C++ programs. That is, they shou
ld |
| 21 include the following: |
| 22 ```c |
| 23 #ifdef __cplusplus |
| 24 extern "C" { |
| 25 # endif |
| 26 |
| 27 /* ... body of file ... */ |
| 28 |
| 29 #ifdef __cplusplus |
| 30 } |
| 31 # endif |
| 32 ``` |
| 33 - Header files should be self-contained and end in .h. |
| 34 - All header files should have a #define guard to prevent multiple inclusion. |
| 35 To guarantee uniqueness they should be based on the file's path. |
| 36 |
| 37 For public headers: include/grpc/grpc.h --> GRPC_GRPC_H |
| 38 |
| 39 For private headers: |
| 40 src/core/channel/channel_stack.h --> GRPC_INTERNAL_CORE_CHANNEL_CHANNEL_STACK_
H |
| 41 |
| 42 C99 Features |
| 43 ------------ |
| 44 |
| 45 - Variable sized arrays are not allowed |
| 46 - Do not use the 'inline' keyword |
| 47 - Flexible array members are allowed (https://en.wikipedia.org/wiki/Flexible_arr
ay_member) |
| 48 |
| 49 Comments |
| 50 -------- |
| 51 |
| 52 Within public header files, only `/* */` comments are allowed. |
| 53 |
| 54 Within implementation files and private headers, either single line `//` |
| 55 or multi line `/* */` comments are allowed. Only one comment style per file is |
| 56 allowed however (i.e. if single line comments are used anywhere within a file, |
| 57 ALL comments within that file must be single line comments). |
| 58 |
| 59 Symbol Names |
| 60 ------------ |
| 61 |
| 62 - Non-static functions must be prefixed by grpc_ |
| 63 - static functions must not be prefixed by grpc_ |
| 64 - enumeration values and #define names are uppercased, all others are lowercased |
| 65 - Multiple word identifiers use underscore as a delimiter (NEVER camel casing) |
OLD | NEW |