| If ``mem2`` fails to apply for memory, the ``CHECK_PTR`` will return a
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.
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
| In summary: It is not recommended to encapsulate statements that
change control flow, such as return, goto, continue, and break in
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
...
@@ -2349,12 +2337,9 @@ Rec 6.3 Ensure that function-like macros contain no more than 10 lines (not incl
Variables
Variables
*********
*********
| In C language coding, variables are the most important except for
| In C language coding, variables are the most important except for functions.
functions.
| When using a variable, you should always follow the principle of “single responsibility”.
| When using a variable, you should always follow the principle of
| By scope, variables can be classified into global variables and local variables.
“single responsibility”.
| By scope, variables can be classified into global variables and local
variables.
Global Variables
Global Variables
================
================
...
@@ -2426,8 +2411,7 @@ initialized before being used as rvalues.
...
@@ -2426,8 +2411,7 @@ initialized before being used as rvalues.
| For example, the PCLint tool reports a warning for the following two
| For example, the PCLint tool reports a warning for the following two
examples.
examples.
Warning 530: Symbol ‘data’ (line …) not initialized Warning 644:
.. warning:: Symbol ‘data’ (line …) not initialized Warning 644: Variable ‘data’ (line …) may not have been initialized
Variable ‘data’ (line …) may not have been initialized
Rule 7.3 Forbid invalid and redundant variable initialization.
Rule 7.3 Forbid invalid and redundant variable initialization.