[previous] MISRA-C:2004  Rule  17.5:  (Advisory) [next] The declaration of objects should contain no more than 2 levels of pointer indirection.
Use of more than 2 levels of indirection can seriously impair the ability to understand the behaviour of the code, and should therefore be avoided.

typedef int8_t * INTPTR;

struct s 
{
   int8_t *   s1; /* compliant     */
   int8_t **  s2; /* compliant     */
   int8_t *** s3; /* not compliant */
};

struct s *   ps1; /* compliant     */
struct s **  ps2; /* compliant     */
struct s *** ps3; /* not compliant */

int8_t **  (   *pfunc1 )(); /* compliant     */
int8_t **  (  **pfunc2 )(); /* compliant     */
int8_t **  ( ***pfunc3 )(); /* not compliant */
int8_t *** (  **pfunc4 )(); /* not compliant */

void function( int8_t *   par1,
               int8_t **  par2,
               int8_t *** par3,                /* not compliant */
               INTPTR *   par4,
               INTPTR *   const * const par5,  /* not compliant */
               int8_t *   par6[],
               int8_t **  par7[] )             /* not compliant */
{
   int8_t *   ptr1;
   int8_t **  ptr2;
   int8_t *** ptr3;               /* not compliant */
   INTPTR *   ptr4;
   INTPTR *   const * const ptr5; /* not compliant */
   int8_t *   ptr6[10];
   int8_t **  ptr7[10];
}

Explanation of types:

* par1 and ptr1 are of type pointer to int8_t.

* par2 and ptr2 are of type pointer to pointer to int8_t.

* par3 and ptr3 are of type pointer to a pointer to a pointer to int8_t. This is three levels and is not compliant.

* par4 and ptr4 are expanded to a type of pointer to a pointer to int8_t.

* par5 and ptr5 are expanded to a type of const pointer to a const pointer to a pointer to int8_t. This is three levels and is not compliant.

* par6 is of type pointer to pointer to int8_t because arrays are converted to a pointer to the initial element of the array.

* ptr6 is of type pointer to array of int8_t.

* par7 is of type pointer to pointer to pointer to int8_t because arrays are converted to a pointer to the initial element of the array. This is three levels and is not compliant.

* ptr7 is of type array of pointer to pointer to int8_t. This is compliant.


QAC messages that encompass this guideline:

3260 Typedef defined with more than 2 levels of indirection.
3261 Member of struct/union defined with more than 2 levels of indirection.
3262 Object defined or declared with more than 2 levels of indirection.
3263 Function defined or declared with a return type which has more than 2 levels of indirection.



(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