Clang编译器的C枚举数据类型是什么? [英] What's the data-type of C enum of Clang compiler?
问题描述
我发布了其他问题:什么类型我应该使用C枚举的二进制表示?,通过答案,我必须知道我的编译器的枚举数据类型。
I posted other question: 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.
什么是数据 - Cang编译器中的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
标准要求是:
类型的选择是实现定义的,但是能够表示所有成员的价值枚举。
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.
这篇关于Clang编译器的C枚举数据类型是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!