我不知道这种结构和指针的使用

时间:2018-03-22 07:06:18

标签: c++ c struct

任何人都可以帮助我这行代码做什么:

((struct mac_tb_ind *) (tb_p->data))->first_bit = 0; 

结构体定义如下:(tb_p是mem_block_t的种类)

struct mac_tb_ind {
    unsigned char  *data_ptr;
    unsigned short  size;
    unsigned char   error_indication;
    unsigned char   first_bit;
};

typedef struct mem_block_t {
    struct mem_block_t *next;
    struct mem_block_t *previous;
    unsigned char       pool_id;
    unsigned char      *data;
} mem_block_t;

1 个答案:

答案 0 :(得分:1)

tb_p->data指针存储在data

(struct mac_tb_ind *) (tb_p->data)对指针进行类型转换,以便编译器知道如何解释它

((struct mac_tb_ind *) (tb_p->data))->first_bit = 0; first_bit中存储的值设置为0