MISRA.VAR.MIN.VISName visibility is too wide. MISRA-C Rule 8.7 (required): Objects shall be defined at block scope if they are only accessed from within a single function.The scope of objects shall be restricted to functions where possible. File scope shall only be used where objects need to have either internal or external linkage. Where objects are declared at file scope Rule 8.10 applies. It is considered good practice to avoid making identifiers global except where necessary. Whether objects are declared at the outermost or innermost block is largely a matter of style. "Accessing" means using the identifier to read from, write to, or take the address of the object. MISRA-C++ Rule 3—4—1 (required): An identifier declared to be an object or type shall be defined in a block that minimizes its visibilityRationaleDefining variables in the minimum block scope possible reduces the visibility of those variables and therefore reduces the possibility that these identifiers will be used accidentally. A corollary of this is that global objects (including singleton function objects) shall be used in more than one function. Examplevoid f ( int32_t k ) { int32_t j = k * k; // Non-compliant { int32_t i = j; // Compliant std::cout << i << j << std::endl; } } In the above example, the definition of 'j' could be moved into the same block as 'i', reducing the possibility that 'j' will be incorrectly used later in 'f'. |