C语言枚举数据类型?

标签 c

<分区>

Possible Duplicate:
What is the size of an enum in C?

重新定义 C 语言枚举:用户无法控制枚举变量的大小。谁能解释一下?

最佳答案

此语句来自C99 6.7.2.2p4

Each enumerated type shall be compatible with char, a signed integer type, or an unsigned integer type. The choice of type is implementation-defined,108) but shall be capable of representing the values of all the members of the enumeration.

108) An implementation may delay the choice of which integer type until all enumeration constants have been seen.

这允许编译器做出它认为是特定枚举的最佳选择。枚举可能不是在机器之间传递的二进制消息中使用的最佳选择。但是,您可以使用整数类型,然后转换回枚举类型。

关于C语言枚举数据类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11644651/

相关文章:

c - 找到第一个可用位的最佳方法

c++ - Makefile子目录递归

c : gets() and fputs() are dangerous functions?

C程序: pass function as parameter to another function to create thread

c++ - C语言中有字符串吗?

c - C中队列的链表实现——关于空条件和空闲

c - 您使用什么字母作为常量占位符?

c - 包含两个指针的结构的大小

MySQL查询选择表中时间值等于当前时间的字段

c - 内存性能/缓存难题