计算一个结构体内成员地址的偏移量的两种方法

一、有时候需要需要看一下一个结构体内成员地址的偏移量,下面介绍两种实现方法。 二、实现方法。 1、方法一,包含头文件#include <stddef.h>,调用函数offsetof(struct s, i)来实现。 2、方法二,使用&(((s1*)0)->i)的形式。 三、实例测试。 1、c代码        #include <stddef.h>        #include <stdio.h
相关文章
相关标签/搜索