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