小编sle*_*dog的帖子

c - 不能取位域的地址

为什么不能取位域的地址?

如何制作指向位字段的指针?

这是代码......

struct bitfield {
    unsigned int a: 1;
    unsigned int b: 1;
    unsigned int c: 1;
    unsigned int d: 1;
};

int main(void)
{
    struct bitfield pipe = {
        .a = 1, .b = 0,
        .c = 0, .d = 0
    };
    printf("%d %d %d %d\n", pipe.a,
            pipe.b, pipe.c, pipe.d);
    printf("%p\n", &pipe.a); /* OPPS HERE */
    // error: cannot take address of bit-field ...
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c pointers syntax-error memory-address bit-fields

14
推荐指数
3
解决办法
2万
查看次数

标签 统计

bit-fields ×1

c ×1

memory-address ×1

pointers ×1

syntax-error ×1