| 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.