Categories
Development

Is it OK to use global variables when they are only used in one file? Are const/constexpr global variables generally considered OK to use?

I understand that global variables should be avoided whenever possible for a few reasons: It’s hard to debug if a global variable has an invalid value (since every function has access to it) For multiple global variables over multiple files, if there are any dependencies on the global variables (e.g., if you have a = […]