开发者

enum element limit

Is there a maximum number of allowable enum elements in C++?

(Question arose from answer to my previous question on d开发者_运维问答efines)


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 #defines. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜