8.1 Type names

8.1.1 Do not use multiple levels of pointer indirection

In C++, at most one level of pointer indirection combined with references is sufficient to express any algorithm or API. Instead of using multidimensional arrays, an array of containers or nested containers should be used. Code reliant on more than one level of pointer indirection will be less readable and more difficult to maintain.

#include <cstdint>                          
#include <vector>
               
void foo (int32_t const * const * const pp); // @@- Non-Compliant -@@
void foo (int32_t const * const & rp);       // @@+ Compliant +@@
void foo (int32_t const (& ra) [10]);        // @@+ Compliant +@@
void foo (std::vector <int32_t> const & rv); // @@+ Compliant +@@

Exception

Use of argv in the main function is allowed.

For Example:

// main1 .cpp
// Compliant: argv not used
int main ();
// main2 .cpp
// Compliant: 2 levels of pointer indirection in argv
int main (int argc , char * argv []);
// main3 .cpp
// Compliant: 2 levels of pointer indirection in argv
int main (int argc , char * * argv );

References

  • JSF AV C++ Rev C – 169
  • JSF AV C++ Rev C – 170
  • MISRA C++:2008 – 5-0-19

Click here for references