Skip to content
Snippets Groups Projects
Commit 9b2e6f13 authored by Gururaj Shetty's avatar Gururaj Shetty
Browse files

Update C Coding Style Guide.rst

parent e4fde489
No related branches found
No related tags found
No related merge requests found
......@@ -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.
--------------------------------------------------------------
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment