Can someone explain when you're supposed to use the static keyword before global variables or constants defined in header files?
For example, lets say I have a header file with the line:
const float kGameSpriteWidth = 12.0f;
Should this have static in front of const or not? What are some best practices for using static?
staticis implied (i.e. it'sstaticby default) for all global namespaceconst-qualified variables, though I would recommend qualifying it asstaticregardless so that intent is made clear.externto share variables between source files? The answers there explain how to share values — and a key part of the is using a header to declare (but not define) variables that are shared. If you don't have a header to put the declaration in, the variable definition should be static. If you do have a header for it, include the header both where the variable is defined (that will be one source file only) and where it is used (could be many source files).