I agree with high_flyer, global variables are not evil, but when possible, use encapsulation.
The golden rule in C is that a variable should not be a global if it only needs to be accessed by functions in the same file (this becomes a 'must' in many coding policies used by companies). If a variable only needs to be read, it should be file-local and a function provided to provide the contents.
In C++ you have class encapsulation instead of file encapsulation. Only use globals if it makes sense to do so.
Bookmarks