MISRA.PTR.TO_PTR_TO_PTRPointer declaration has more than two levels of indirection.
MISRA C 2012 Rule 18.5: Declarations should contain no more than two levels of pointer nestingCategory: Advisory Analysis: Decidable, Single Translation Unit Applies to: C90, C99 AmplificationNo more than two pointer declarators should be applied consecutively to a type. Any typedef-name appearing in a declaration is treated as if it were replaced by the type that it denotes. RationaleThe use of more than two levels of pointer nesting can seriously impair the ability to understand the behaviour of the code, and should therefore be avoided. Exampletypedef int8_t * INTPTR; void function ( int8_t ** arrPar[ ] ) /* Non-compliant */ { int8_t ** obj2; /* Compliant */ int8_t *** obj3; /* Non-compliant */ INTPTR * obj4; /* Compliant */ INTPTR * const * const obj5; /* Non-compliant */ int8_t ** arr[ 10 ]; /* Compliant */ int8_t ** ( *parr )[ 10 ]; /* Compliant */ int8_t * ( **pparr )[ 10 ]; /* Compliant */ } struct s { int8_t * s1; /* Compliant */ int8_t ** s2; /* Compliant */ int8_t *** s3; /* Non-compliant */ }; struct s * ps1; /* Compliant */ struct s ** ps2; /* Compliant */ struct s *** ps3; /* Non-compliant */ int8_t ** ( *pfunc1 )( void ); /* Compliant */ int8_t ** ( **pfunc2 )( void ); /* Compliant */ int8_t ** ( ***pfunc3 )( void ); /* Non-compliant */ int8_t *** ( **pfunc4 )( void ); /* Non-compliant */ Note:
MISRA-C 2004 Rule 17.5 (advisory): The declaration of objects should contain no more than 2 levels of pointer indirectionPointer declaration has more than two levels of 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. Exampletypedef 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:
MISRA-C++ 2008 Rule 5-0-19 (required): The declaration of objects shall contain no more than two levels of pointer indirection.RationaleUse of more than two levels of indirection can seriously impair the ability to understand the behaviour of the code, and therefore should be avoided. Exampletypedef int8_t * INTPTR; struct s { int8_t * s1; // Compliant int8_t ** s2; // Compliant int8_t *** s3; // Non-compliant }; struct s * ps1; // Compliant struct s ** ps2; // Compliant struct s *** ps3; // Non-compliant int8_t ** ( *pfunc1)(); // Compliant int8_t ** ( **pfunc2)(); // Compliant int8_t ** (***pfunc3)(); // Non-compliant int8_t *** ( **pfunc4)(); // Non-compliant void function( int8_t * par1, // Compliant int8_t ** par2, // Compliant int8_t *** par3, // Non-compliant INTPTR * par4, // Compliant INTPTR * const * const par5, // Non-compliant int8_t * par6[], // Compliant int8_t ** par7[]) // Non-compliant { int8_t * ptr1; // Compliant int8_t ** ptr2; // Compliant int8_t *** ptr3; // Non-compliant INTPTR * ptr4; // Compliant INTPTR * const * const ptr5; // Non-compliant int8_t * ptr6[ 10 ]; // Compliant int8_t ** ptr7[ 10 ]; // Compliant } Explanation of types
|