MISRA C:2025 Rule 11.11
R2026bDescription
Pointers shall not be implicitly compared to NULL.1
Rationale
Control expressions in if, while, do,
and for statements, as well as operands of logical operators and the
first operand of the conditional operator, require objects that are essentially Boolean
type. A When a pointer appears directly in these contexts, the compiler implicitly converts
the pointer to a Boolean value. For example, in this code, the pointer
ptr is implicitly converted to
Boolean:
void foo(char* ptr){
//...
if(ptr){
// code...
}
}if (ptr != NULL) instead produces an explicitly
Boolean result from the comparison operator.Polyspace Implementation
Polyspace® reports a violation of this rule when a pointer expression is:
Converted to
boolor a user-defined Boolean typeUsed as an operand of a logical operator (
!,&&,||)Used as the controlling expression of an
if,while,do, orforstatementUsed as the first operand of a conditional (ternary) operator
To report violation on user-defined Boolean types, specify the types using the option
Effective boolean types
(-boolean-types).
Troubleshooting
If you expect a rule violation but Polyspace does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
| Group: Pointer type conversions |
| Category: Required |
| AGC Category: Required |
PQL Name: std.misra_c_2025.R11_11 |
Version History
Introduced in R2026b
1 All MISRA coding rules and directives are © Copyright The MISRA Consortium Limited 2021.
The MISRA coding standards referenced in the Polyspace Bug Finder™ documentation are from the following MISRA standards:
MISRA C:2004
MISRA C:2012
MISRA C:2023
MISRA C:2025
MISRA C++:2008
MISRA C++:2023
MISRA and MISRA C are registered trademarks of The MISRA Consortium Limited 2021.