我是靠谱客的博主 友好大白,这篇文章主要介绍Offsetof的实现,现在分享给大家,希望可以做个参考。

offsetoff-用来计算结构体存储时元素存储地址相对于起始存储地址的一个偏移量的一个宏

实现代码:

#include<stdio.h>

#define Offsetof(struct_name,member_name)  (int)&(((struct_name*)0)->member_name)
struct S
{
    int a;
    char b;
    double c;
};
int main()
{
    struct S s = { 0 };
    printf("%dn", Offsetof(struct S, a));
    printf("%dn", Offsetof(struct S, b));
    printf("%dn", Offsetof(struct S, c));

    return 0;
}

最后

以上就是友好大白最近收集整理的关于Offsetof的实现的全部内容,更多相关Offsetof内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(56)

评论列表共有 0 条评论

立即
投稿
返回
顶部