相关疑难解决方法(0)

你如何在struct上使用offsetof()?

我想要offsetof()参数行mystruct1.我试过了

offsetof(struct mystruct1, rec.structPtr1.u_line.line) 
Run Code Online (Sandbox Code Playgroud)

并且

offsetof(struct mystruct1, line)  
Run Code Online (Sandbox Code Playgroud)

但都不起作用.

union {
    struct mystruct1 structPtr1;
    struct mystruct2 structPtr2;
} rec;

typedef struct mystruct1 {
    union {
        struct {
            short len;
            char buf[2];
        } line;

        struct {
            short len;
        } logo;

    } u_line;
};
Run Code Online (Sandbox Code Playgroud)

c

7
推荐指数
1
解决办法
5831
查看次数

标签 统计

c ×1