kernel_根据结构体成员地址获结构体地址
在同一台机器上,结构体的在内存中分配每个成员变量的偏移地址固定的。
struct fox { unsigned long tail_length; unsigned long weight; _Bool is_fantastic; int length; };
struct fox *a_fox=(struct fox *)malloc(sizeof(struct fox));
&a_fox->length - &a_fox->tail_length = (size_t) &((struct fox *)base)->tail_length-base; 该结构体分配的位置(base)不影响偏移量的值。
若&a_fox->tail_length已知,那么(struct fox *)&a_fox->tail_length就是结构体初始地址,
本文来自博客园,作者:安然春夏,转载请注明原文链接:https://www.cnblogs.com/weixicai/p/17249698.html。测试只能证明程序有错误,而不能证明程序没有错误。你必须非常努力,才能看起来毫不费力。