我的猜测是 C++ 有类似的定义,而 C++0x 增加了一些打字的可能性。合而为一,这意味着理论上您可以拥有的数量受到底层类型的限制(无论它是什么?int大多数时候,我想,C 标准对此还不够明确) )。但在您设置数百万个符号之前,您的编译器将崩溃或可能耗尽内存。
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.
发布评论
评论(3)
没有任何指定的最大值或最小值,这取决于您的实现。然而,请注意附件 B 指出:
作为推荐。但这严格来说只是建议,而不是要求。
There isn't any specified maximum or minimum, it depends on your implementation. However, note that Annex B states:
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.
对于 C 来说,枚举只是一组范围更好的
#define
。无论标准 C 中的详细含义是什么:枚举值是我的猜测是 C++ 有类似的定义,而 C++0x 增加了一些打字的可能性。合而为一,这意味着理论上您可以拥有的数量受到底层类型的限制(无论它是什么?
int
大多数时候,我想,C 标准对此还不够明确) )。但在您设置数百万个符号之前,您的编译器将崩溃或可能耗尽内存。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 aMy 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.