Is there a maximum number of allowable enum
elements in C++?
(Question arose from answer to my previous question on defines)
Is there a maximum number of allowable enum
elements in C++?
(Question arose from answer to my previous question on defines)
There isn't any specified maximum or minimum, it depends on your implementation. However, note that Annex B states:
— Enumeration constants in a single enumeration [4096].
As a recommendation. But this is strictly a recommendation, not a requirement.
The language doesn't specify any such thing. However, compilers can have limits. You'd have to check your compiler docs for that.
In the case of C an enum is just a better scoped set of #define
s. Whatever that means in detail from the standard C: an enum value is of a
type that is compatible with an implementation-defined one of the integral types.
My guess is that C++ has a similar definition and C++0x adds some typing possibility. All in one that would mean the amount you can have of them is theoritically limited by the underlying type (whatever it is? int
most of the time, I suppose, the C standard is not clear enough regarding this). But before you can setup millions of symbols your compiler will crash or probably run out of memory.