struct宏定义一些用法

typedef struct {
    int name;
    int service;
    int server;
    char buf[0];
} item;
#define OFFSET(A, B) (int)&(((A*)0)->B)
#define CONTAINER(PTR, TYPE, FIELD) (TYPE*)((char*)PTR-OFFSE    T(TYPE, FIELD))

第一个,获取变量偏移地址;
第二个,获取变量对应结构体的地址。
 

Categoriesc

Leave a Reply

Your email address will not be published. Required fields are marked *