什么是下面的宏吗? [英] What does the following macro do?
问题描述
在QEMU源$ C $ C,我有一个名为以下,宏offsetof
。谁能告诉我这是什么呢?
in qemu source code, I have the following macro named offsetof
. Can anybody tell me what it does?
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *) 0)->MEMBER)
它以这种方式使用:
It's used in this manner :
offsetof(CPUState, icount_decr.u32)
其中CPUState是一个结构。
where CPUState is a struct.
我觉得它给一个结构内部成员的偏移,但我不知道。
I think it gives the offset of the member inside a struct, but I'm not sure.
编辑:是啊,我发现发生了什么事。 CPUState的定义有一个宏里,我错过了,其中包括可变icount_decr。
Yeah, I found out what was happening. The definition of CPUState had a macro inside, which I missed, which included the variable icount_decr.
推荐答案
它得到的偏移结构的成员。它通过铸造零地址的类型,然后取件的地址的结构这样做。
It gets the offset of the member of a struct. It does so by casting address zero to a struct of that type then taking the address of the member.
这篇关于什么是下面的宏吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!