不是 int 类型的位域? [英] Bit-fields of type other than int?
问题描述
我有一个使用位域的代码,声明如下
I have a code which uses bit-fields declared as follows
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 中使用这个位域构建代码会给出如下警告:
Building the code in MS-VS 2008 using this bit fields gives a warning as below:
imgconvert.c(60) : warning C4214: nonstandard extension used : bit-field types other than int.
- 在使用 int 类型以外的位域时是否有任何问题/潜在问题?为什么会出现警告?
- C99 C 语言规范是否允许除 int 类型以外的位文件?
推荐答案
1] 使用除 int 类型以外的位字段是否有任何问题/潜在问题?为什么会出现警告?
1] Is there any problems/potential issues in using bit fields of type other than int? Why the warning?
由于位域是低级的,如果您使用非标准类型,可能会出现可移植性问题.因此警告 - 请注意它仍然是警告而不是错误.
Since bit-fields are low-level, there may be issues with portability if you are using non-standard types. Hence the warning -- note it is still a warning and not an error.
2] C99 C 语言规范是否允许除 int 类型以外的位文件?
2] Are other than int type bit-fileds they allowed by C99 C language specification?
来自C99的草案:
6.7.2.1 结构和联合说明符
4 位域的类型应为合格或不合格的版本_Bool、signed int、unsigned int 或其他一些实现定义类型.
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.
这篇关于不是 int 类型的位域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!