sizeof a struct member
This question already has an answer here:
sizeof(((struct A*)0)->arr);
Briefly, cast a null pointer to a type of struct A*
, but since the operand of sizeof
is not evaluated, this is legal and allows you to get size of struct members without creating an instance of the struct.
Basically, we are pretending that an instance of it exists at address 0 and can be used for offset and sizeof
determination.
To further elaborate, read this article:
http://www.embedded.com/design/prototyping-and-development/4024941/Learn-a-new-trick-with-the-offsetof--macro
链接地址: http://www.djcxy.com/p/72136.html上一篇: sizeof()结构未知。 为什么?
下一篇: 大小的结构成员