I have many classes in the system that I'm currently developing and in these classes I have an array about the "name" of something. The name should be at most 30 characters.
Initially I used just 10 characters but now I need to increase the limit. Increasing the limit takes time though because I use this kind of array in many places. It would be easier if I used #define NAME_SIZE 30
or something like that and then all I would have to do is change one number instead of around twenty.
However I'm not sure if that's a "legal" thing to do in C++.
It would save me tons of time in the future, that's why I'm asking.
Yes, there is nothing technically wrong with it, except that
#define
is usually inferior to aconst std::size_t MAX_NAME_SIZE = 30;
Even better would be to have a dynamic size, e.g. usingstd::string
.Scott Meyers has an interesting column about systems that use gratuitous fixed sizes, called The Keyhole Problem
Apart from annoynance from users, you also open your systems to all sorts of security issues (e.g. buffer overflow exploits).