NIUCLOUD是一款SaaS管理后台框架多应用插件+云编译。上千名开发者、服务商正在积极拥抱开发者生态。欢迎开发者们免费入驻。一起助力发展! 广告
offsetof可以测出偏移量 ~~~ #include <iostream> #include <stddef.h> struct Person { int a; char b; char buf[64]; int d; }; int main() { struct Person p = {10, 'a', "hello world", 100}; //查看b在里面的偏移量,offsetof需要导包 printf("a off:%d\n", offsetof(struct Person, b)); //4 printf("d = %d\n", *(int *) ((char *) &p + offsetof(struct Person, d))); getchar(); return 0; } ~~~ 输出 ~~~ a off:4 d = 100 ~~~