diff --git a/documentation/source/readme/C Coding Style Guide.rst b/documentation/source/readme/C Coding Style Guide.rst index 195ef2028d623f10660d0a3322898750f7b4c95d..5d8e97ea936cb4172d778dc275fc3da81d96eba9 100644 --- a/documentation/source/readme/C Coding Style Guide.rst +++ b/documentation/source/readme/C Coding Style Guide.rst @@ -269,7 +269,8 @@ Or, variables in simple math functions: { return a * b; } - Type Naming + +Type Naming =========== | Types are named in the UpperCamelCase style. @@ -1125,20 +1126,13 @@ File Header Comments Rule 3.1 File header comments must contain the copyright license. ----------------------------------------------------------------- - -/\* - - Copyright (c) 2020 Huawei Device Co., Ltd. - Licensed under the Apache License, Version 2.0 (the “Licenseâ€); - you may not use this file except in compliance with the License. -- You may obtain a copy of the License at -- ​ -- http://www.apache.org/licenses/LICENSE-2.0 -- ​ -- Unless required by applicable law or agreed to in writing, software +- You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 +- ​Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an “AS IS†BASIS, -- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied. +- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. \*/ @@ -2319,13 +2313,7 @@ leak. Example is as follows: mem2 = MemAlloc(...); CHECK_PTR(mem2, ERR_CODE_XXX); // Wrong: Memory leak. -| If ``mem2`` fails to apply for memory, the ``CHECK_PTR`` will return a - message instead of releasing ``mem1``. -| Besides, the name of the ``CHECK_PTR`` macro is not good. The macro - name only reflects the check action and does not specify the result. - Readers can see that a failure is returned when the pointer is null - only after viewing the macro implementation. It’s not inherently - obvious. +If ``mem2`` fails to apply for memory, the ``CHECK_PTR`` will return a message instead of releasing ``mem1``. Besides, the name of the ``CHECK_PTR`` macro is not good. The macro name only reflects the check action and does not specify the result. Readers can see that a failure is returned when the pointer is null only after viewing the macro implementation. It’s not inherently obvious. | In summary: It is not recommended to encapsulate statements that change control flow, such as return, goto, continue, and break in @@ -2349,12 +2337,9 @@ Rec 6.3 Ensure that function-like macros contain no more than 10 lines (not incl Variables ********* -| In C language coding, variables are the most important except for - functions. -| When using a variable, you should always follow the principle of - “single responsibilityâ€. -| By scope, variables can be classified into global variables and local - variables. +| In C language coding, variables are the most important except for functions. +| When using a variable, you should always follow the principle of “single responsibilityâ€. +| By scope, variables can be classified into global variables and local variables. Global Variables ================ @@ -2426,8 +2411,7 @@ initialized before being used as rvalues. | For example, the PCLint tool reports a warning for the following two examples. - Warning 530: Symbol ‘data’ (line …) not initialized Warning 644: - Variable ‘data’ (line …) may not have been initialized +.. warning:: Symbol ‘data’ (line …) not initialized Warning 644: Variable ‘data’ (line …) may not have been initialized Rule 7.3 Forbid invalid and redundant variable initialization. --------------------------------------------------------------