AutosarC++18_10-M7.1.2¶
A pointer or reference parameter in a function shall be declared as pointer to const or reference to const if the corresponding object is not modified
Required inputs: IR
| Level | required |
|---|---|
| Target | implementation |
| Enforcement | automated |
Rationale
This rule leads to greater precision in the definition of the function interface. The const qualification shall be applied to the object pointed to, not to the pointer, since it is the object itself that is being protected.
Exception
This rule does not apply if the parameter object is modified by any of the functions in a set of overriding functions.
Example
void myfunc( int16_t * param1,
const int16_t * param2,
int16_t * param3,
int16_t * const param4)
// param1: Addresses an object which is modified - Compliant
// param2: Addresses an object which is not modified – Compliant
// param3: Addresses an object which is not modified – Non-compliant
// param4: Addresses an object which is not modified – Non-compliant
{
*param1 = *param2 + *param3 + *param4;
// Data at address param3 and param4 have not been changed
}
Note
For legal reasons, this rule’s description is not part of the public documentation.