什么是数据类型锵编译器Ç枚举? [英] What's the data-type of C enum of Clang compiler?
问题描述
我张贴的其他问题:<一href=\"http://stackoverflow.com/questions/3509470/what-type-should-i-use-for-binary-re$p$psentation-of-c-enum\">http://stackoverflow.com/questions/3509470/what-type-should-i-use-for-binary-re$p$psentation-of-c-enum,和答案,我要知道我的编译器的枚举数据类型。
I posted other question: http://stackoverflow.com/questions/3509470/what-type-should-i-use-for-binary-representation-of-c-enum, and by the answer, I have to know my compiler's enum data-type.
什么是上锵编译数据C型枚举的?
What's the data-type of C enum on Clang compiler?
推荐答案
最喜欢的(全部,也许)C编译器,一个枚举类型的大小可以变化。下面是一个例子程序和它的输出:
Like most (all, maybe) C compilers, the size of an enumerated type can vary. Here's an example program and its output:
#include <stdio.h>
typedef enum
{
val1 = 0x12
} type1;
typedef enum
{
val2 = 0x123456789
} type2;
int main(int argc, char **argv)
{
printf("1: %zu\n2: %zu\n", sizeof(type1), sizeof(type2));
return 0;
}
输出:
1: 4
2: 8
所有的标准要求是:
All that the standard requires is:
类型的选择是实现定义的,但应能重新presenting枚举的所有成员的值。
The choice of type is implementation-defined, but shall be capable of representing the values of all the members of the enumeration.
一个快速网络搜索不转了所指定的行为铿锵手册,但一个是几乎可以肯定在某个地方。
A quick web search didn't turn up a clang manual that specified its behaviour, but one is almost certainly out there somewhere.
这篇关于什么是数据类型锵编译器Ç枚举?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!