MISRA C:2012 Rule 11.9
The macro NULL shall be the only permitted form of integer null pointer constant
Description
Rule Definition
The macro NULL shall be the only permitted form of integer null pointer constant.
Rationale
The following expressions allow the use of a null pointer constant:
Assignment to a pointer
The
==
or!=
operation, where one operand is a pointerThe
?:
operation, where one of the operands on either side of : is a pointer
Using NULL
rather than 0 makes it clear that
a null pointer constant was intended.
Polyspace Implementation
The checker flags the assignment of the constant zero to pointers, equalities (or inequalities) comparing pointers with the constant zero, and other similar expressions listed in the MISRA C™: 2012 documentation.
Following the updates in MISRA C: 2012 Technical Corrigendum 1, the checker allows the use of {0} to initialize aggregates containing only pointers, for instance, arrays of pointers or structures (or unions) with only a pointer field. If an aggregate contains multiple fields, the initialization is still flagged. In these cases, you should use the macro NULL for pointer fields and 0 for integer fields to distinguish between them.
Troubleshooting
If you expect a rule violation but do not see it, refer to Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Pointer Type Conversions |
Category: Required |
AGC Category: Readability |
Version History
Introduced in R2014b