20.3.1.1.  Globals and const

[ fromfile: globals.xml id: constglobals ]

Example 20.8. src/const/globals/chunk1.cpp

const int NN = 10;      // file scope
const int MM = 44;      // file scope
extern const int QQ = 7; // can be accessed from other files   

int main() {
// NN = 12;        // error
   int array[NN];  // okay
// QQ++;           // error
   double darray[QQ];
   return 0;
}


Example 20.9. src/const/globals/chunk2.cpp

extern const int NN = 22;     // a different constant
extern const int MM;          // error
// declare global constant - storage allocated elsewhere
extern const int QQ;    // external declaration 
void newFunction() {
   int x = QQ + NN;
}