Next: High Integrity CPP Rule 8.3.3  Up: 8.3 Language Restrictions  Previous: High Integrity CPP Rule 8.3.1  Contents

High Integrity CPP Guideline 8.3.2   Restrict the use of the 'extern' keyword. Do not write 'extern' where it is implicit.

Justification

Keyword 'extern' is used to specify external linkage. It is implicit in function declarations written at global and namespace scope and should not be used in such declarations. Global and namespace scope const objects and typedefs have internal linkage. Recommended practice is to define all const objects with internal linkage in header files only. Hence extern qualification is only necessary when declaring data objects with external linkage.

   
   // Header file:
   const float s = 3.0E8F;    // internal linkage constant definition
   extern int a;              // external linkage object declaration
   int foo( int );            // external linkage function declaration
   
   // Implementation file:
   int a = 2;                 // external linkage object definition
See also

Rule 11.2

Reference

Stroustrup;


HICPP VERSION 2.4  http://www.codingstandard.com   Copyright: © 2007 THE PROGRAMMING RESEARCH GROUP