Rule Definition
Declaring names into appropriate namespaces reduces the names found during lookup, helping to ensure that the names found meet developer expectations.
Remediation
Ensure that in global space only extern linkages, namespace and main function are present
Violation Code Sample
void f1 ( int32_t ); // Non-compliant
int32_t x1; // Non-compliant
namespace
{
void f2 ( int32_t ); // Compliant
int32_t x2; // Compliant
}
Fixed Code Sample
namespace MY_API
{
void b2 ( int32_t ); // Compliant
int32_t x2; // Compliant
}
int32_t main ( ) // Compliant - main function
{
}
Reference
MISRA C++, 2008, 7-3-1: The global namespace shall only contain main, namespace declarations and extern "C" declarations.
Related Technologies
Technical Criterion
Documentation - Naming Convention Conformity
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.