C:这个宏是什么意思? [英] C: What does this macro mean?

查看:167
本文介绍了C:这个宏是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您如何阅读此宏的第二行? (*)0在这种情况下是什么意思?

How do you read the second line of this macro? What does (type *)0 mean in this context?

#define container_of(ptr, type, member) ({ \
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})

推荐答案

您正在找到((type *)0)->member类型.它实际上并没有取消引用指针(我告诉你这将是疯狂.疯狂!)

You're finding the type of ((type *)0)->member. It's not actually dereferencing the pointer (that would be madness, I tell you. Madness!)

这是C的怪异之处.也许如果他们写typeof(type.member)会更有意义,但遗憾的是这是不允许的.

It's a weirdness of C. Maybe it would make more sense if they wrote typeof(type.member) but sadly that is not allowed.

这篇关于C:这个宏是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆