c - 为什么需要说明符限定符列表?

标签 c gcc bit-fields specifier

我编译了这个(gcc 编译器):

#include <stdio.h>

main() {

    struct {
        a:1;
        b:2;
    } t;

    t.b=6;
    t.a=2;
    printf("%d %d",t.a,t.b);
}

显示的错误是:

'a' 之前的预期说明符-限定符列表

为什么在未命名数据变量默认取int时需要它。请解释...

最佳答案

这是 C language standard 所要求的.根据 6.7.2.1 第 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 - 为什么需要说明符限定符列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10056451/

相关文章:

编译器 gcc :error; no such file or directory

c - strcat() 在 C 内部如何工作?

c - makefile 包含静态库 - C

linux - 链接时 LD_LIBRARY_PATH 和 -L 有什么区别?

gcc - 为什么 gcc -Og 不生成源代码行映射?

c++ - 为什么我的程序不检查位域成员的值,即使有 "if"语句?

C编程条件运算符

c - 考虑到优先级和结合性,如何解决这个表达式?

rust - 在编译位域的Rust并集时获取E0658

c++ - 大整数隐式截断为无符号类型