6.1 Global

All variables defined outside of the definition of a subroutine are global. Global variables are visible at least within the same source file, from the point of the definition.

Without the use of the keyword static, a global variable is accessible by the linker. This means that such a variable can be referenced by another source code. However, if a global variable is defined with the keyword static, it is only visible in the local source file.

Personally, I think static should be the default to limit visibility of global variables. However, C/C++ exposes global variables to other source files by default.



Copyright © 2006-09-25 by Tak Auyeung