AutosarC++19_03-M4.10.2¶
Literal zero (0) shall not be used as the null-pointer-constant
Required inputs: IR
Bad code (literal zero as null):
int* ptr = 0; // ERROR: ambiguous - is this int zero or null pointer?
if (ptr == 0) { } // Unclear intent
Good code (using NULL macro):
int* ptr = NULL; // OK: explicit null pointer constant
if (ptr == NULL) { } // Clear intent
Good code (using C++11 nullptr):
int* ptr = nullptr; // OK: type-safe null pointer
if (ptr == nullptr) {} // Clear and type-safe
Note
For legal reasons, this rule’s description is not part of the public documentation.