Added section about variable initialization

pull/7243/head
David Garcia Quintas 9 years ago
parent 2a16a028e0
commit fed3e3b070
  1. 29
      doc/c-style-guide.md

@ -9,16 +9,17 @@ Here we document style rules for C usage in the gRPC Core library.
General General
------- -------
- Layout rules are defined by clang-format, and all code should be passed through - Layout rules are defined by clang-format, and all code should be passed
clang-format. A (docker-based) script to do so is included in through clang-format. A (docker-based) script to do so is included in
[tools/distrib/clang\_format\_code.sh] (../tools/distrib/clang_format_code.sh). [tools/distrib/clang\_format\_code.sh](../tools/distrib/clang_format_code.sh).
Header Files Header Files
------------ ------------
- Public header files (those in the include/grpc tree) should compile as pedantic C89 - Public header files (those in the include/grpc tree) should compile as
- Public header files should be includable from C++ programs. That is, they should pedantic C89
include the following: - Public header files should be includable from C++ programs. That is, they
should include the following:
```c ```c
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -34,17 +35,27 @@ Header Files
- All header files should have a #define guard to prevent multiple inclusion. - All header files should have a #define guard to prevent multiple inclusion.
To guarantee uniqueness they should be based on the file's path. To guarantee uniqueness they should be based on the file's path.
For public headers: include/grpc/grpc.h --> GRPC_GRPC_H For public headers: `include/grpc/grpc.h``GRPC_GRPC_H`
For private headers: For private headers:
src/core/channel/channel_stack.h --> GRPC_INTERNAL_CORE_CHANNEL_CHANNEL_STACK_H `src/core/channel/channel_stack.h`
`GRPC_INTERNAL_CORE_CHANNEL_CHANNEL_STACK_H`
Variable Initialization
-----------------------
When declaring a (non-static) pointer variable, always initialize it to `NULL`.
Even in the case of static pointer variables, it's recommended to explicitly
initialize them to `NULL`.
C99 Features C99 Features
------------ ------------
- Variable sized arrays are not allowed - Variable sized arrays are not allowed
- Do not use the 'inline' keyword - Do not use the 'inline' keyword
- Flexible array members are allowed (https://en.wikipedia.org/wiki/Flexible_array_member) - Flexible array members are allowed
(https://en.wikipedia.org/wiki/Flexible_array_member)
Comments Comments
-------- --------

Loading…
Cancel
Save