global integral constants
Often in a project, there is a need for some global integral constants (which may be used as array sizes).
For example, in a recent project, I was working on a hardware emulator which has a fixed number of analog inputs. so in Globals.h I had
Code:
namespace NSP // platform name
{
static const unsigned int NUM_INPUTS = 20;
} // namespace NSP
but it was mentioned to me that static used in this fashion is deprecated, and the preferable solution is to use an unnamed namespace. so then we have
Code:
namespace NSP // platform name
{
namespace // anon
{
const unsigned int NUM_INPUTS = 20;
} // namespace anon
} // namespace NSP
and ye standard gods were appeased.
but after a bit of unrelated research today, I've discovered that unnamed namespaces in headers are a no-no as they can violate ODR.
so what's the correct way? I don't like the "enum-hack" (for one thing, you can't take the address of it if you need to).