[previous] MISRA-C:2004  Rule  16.7:  (Advisory) [next] A pointer parameter in a function prototype should be declared as pointer to const if the pointer is not used to modify the addressed object.
This rule leads to greater precision in the definition of the function interface. The const qualification should be applied to the object pointed to, not to the pointer, since it is the object itself that is being protected.

For example:

void myfunc( int16_t * param1, const int16_t * param2, int16_t * param3 )
/* param1: Addresses an object which is modified - no const
   param2: Addresses an object which is not modified - const required
   param3: Addresses an object which is not modified - const missing */
{
    *param1 = *param2 + *param3;        
    return;
}
/* data at address param3 has not been changed, 
   but this is not const therefore not compliant */


QAC messages that encompass this guideline:

3673 The object addressed by the pointer parameter '%s' is not modified and so the pointer could be of type 'pointer to const'.



(c) The Motor Industry Research Association, 2004
QA C Source Code Analyser 8.1.2
MISRA-C:2004 Compliance Module 3.2
© 2013 Programming Research
www.programmingresearch.com
Personality Groups | Glossary | Message Index | MISRA-C:2004 Rule Index Contents