Clang编译器的C enum的数据类型是什么?

Eon*_*nil 5 c enums types clang

我发布了其他问题:我应该使用什么类型的C enum的二进制表示?,通过答案,我必须知道我的编译器的枚举数据类型.

Clang编译器上C enum的数据类型是什么?

Car*_*rum 8

像大多数(所有,可能)C编译器一样,枚举类型的大小可以变化.这是一个示例程序及其输出:

#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;
}
Run Code Online (Sandbox Code Playgroud)

输出:

1: 4
2: 8
Run Code Online (Sandbox Code Playgroud)

标准要求的所有内容是:

类型的选择是实现定义的,但应能够表示枚举的所有成员的值.

一个快速的网络搜索没有出现一个指定其行为的铿锵手册,但一个人几乎肯定在某处.