我有一个使用如下声明的位域的代码
typedef struct my{
const char *name;
uint8_t is_alpha : 1;
uint8_t is_hwaccel : 1;
uint8_t x_chroma_shift;
uint8_t y_chroma_shift;
} mystr;
uint8_t
类型定义为 unsigned char
。
使用此位字段在 MS-VS 2008 中构建代码会出现如下警告:
imgconvert.c(60) : warning C4214: nonstandard extension used : bit-field types other than int.
- 使用非 int 类型的位字段是否有任何问题/潜在问题?为什么要发出警告?
- C99 C 语言规范是否允许除 int 类型的位文件外?
最佳答案
1] Is there any problems/potential issues in using bit fields of type other than int? Why the warning?
由于位字段是低级的,如果您使用非标准类型,则可能存在可移植性问题。因此出现了警告——请注意,它仍然是警告,而不是错误。
2] Are other than int type bit-fileds they allowed by C99 C language specification?
摘自C99草案:
6.7.2.1 Structure and union specifiers
4 A bit-field shall have a type that is a qualified or unqualified version of _Bool, signed int, unsigned int, or some other implementation-defined type.
关于c - 非 int 类型的位字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2280492/