Using unnamed namespaces instead of static globals
The larger a program, the greater the chances are you could run into name collisions when your program is linked to multiple translation units. Functions or variables that are declared in a source file, and are supposed to be local to the translation unit, may collide with other similar functions or variables declared in another translation unit.
That is because all the symbols that are not declared static have external linkage and their names must be unique throughout the program. The typical C solution for this problem is to declare those symbols as static, changing their linkage from external to internal and therefore making them local to a translation unit. An alternative is to prefix the names with the name of the module or library they belong to. In this recipe, we will look at the C++ solution for this problem.
Getting ready
In this recipe, we will discuss concepts such as global functions and static functions...